Unable to SendKeys to a token field

I am trying to pass in a four digit OTP into four fields but i keep getting the error that the field cannot be set to the value. See logs below. How can i possibly send the digits successfully? Thanks in advance.
App page


Script
//This section handles OTP validation

driver .findElement(By. xpath ("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.view.ViewGroup/android.widget.TextView[1]")).sendKeys(""+0);

driver .findElement(By. xpath ("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.view.ViewGroup/android.widget.TextView[2]")).sendKeys(""+7);

driver .findElement(By. xpath ("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.view.ViewGroup/android.widget.TextView[3]")).sendKeys(""+5);

driver .findElement(By. xpath ("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.view.ViewGroup/android.widget.TextView[4]")).sendKeys(""+0);

Appium Console Output
org.openqa.selenium.InvalidElementStateException: Cannot set the element to β€˜3’. Did you interact with the correct element?

Build info: version: β€˜3.141.59’, revision: β€˜e82be7d358’, time: β€˜2018-11-14T08:17:03’

System info: host: β€˜Oscar-Air’, ip: β€˜fe80:0:0:0:835:fcea:7592:523a%en0’, os.name: β€˜Mac OS X’, os.arch: β€˜x86_64’, os.version: β€˜10.15.4’, java.version: β€˜1.8.0_191’

Driver info: io.appium.java_client.AppiumDriver

Capabilities {appActivity: loandirect.com.loandirect.c…, appPackage: loandirect.com.loandirect, automationName: uiautomator2, databaseEnabled: false, desired: {appActivity: loandirect.com.loandirect.c…, appPackage: loandirect.com.loandirect, automationName: uiautomator2, deviceName: Android Emulator, newCommandTimeout: 60, platformName: android, platformVersion: 8.1.0, udid: emulator-5554}, deviceApiLevel: 27, deviceManufacturer: Google, deviceModel: Android SDK built for x86, deviceName: emulator-5554, deviceScreenDensity: 400, deviceScreenSize: 1080x2160, deviceUDID: emulator-5554, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, newCommandTimeout: 60, pixelRatio: 2.5, platform: LINUX, platformName: Android, platformVersion: 8.1.0, statBarHeight: 60, takesScreenshot: true, udid: emulator-5554, viewportRect: {height: 1980, left: 0, top: 60, width: 1080}, warnings: {}, webStorageEnabled: false}

Session ID: 88d8e1dd-d933-40ee-bdcb-0a56736d52fc

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)

at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)

at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)

at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)

at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)

at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)

at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)

at io.appium.java_client.MobileElement.execute(MobileElement.java:1)

at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)

at io.appium.java_client.MobileElement.setValue(MobileElement.java:97)

at login.Login.loginWithValidCredentials(Login.java:48)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134)

at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:597)

at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)

at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)

at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:816)

at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)

at java.util.ArrayList.forEach(ArrayList.java:1257)

at org.testng.TestRunner.privateRun(TestRunner.java:766)

at org.testng.TestRunner.run(TestRunner.java:587)

at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)

at org.testng.SuiteRunner.run(SuiteRunner.java:286)

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)

at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1109)

at org.testng.TestNG.runSuites(TestNG.java:1039)

at org.testng.TestNG.run(TestNG.java:1007)

at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)

at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

===============================================

Default test

Tests run: 1, Failures: 1, Skips: 0

===============================================

===============================================

Default suite

Total tests run: 1, Passes: 0, Failures: 1, Skips: 0

===============================================

you should use keyboard with this screen.

new Actions(driver).sendKeys(text).perform();
2 Likes

@Aleksei, thank you very much for the prompt response. This worked very well for me.

Thank Aleksei, It worked for me, also work well on the real device