Error getting on Appium, Cannot set the element to 'value'. Did you interact with the correct element?

Viewed 3917

I am doing automation of the app using appium. I am able to lunch the app but I go for login, it can read the XPath for login. But appium is unable to enter the mobile number. For mobile device, I am using the emulator.

This is my code:

driver.findElement(By.xpath(props.getProperty("mobile"))).sendKeys("123456");

This is my Xpath:

mobile=//android.widget.EditText[@text='Mobile']

Error facing:

Encountered internal error running command: io.appium.uiautomator2.common.exceptions.InvalidElementStateException: Cannot set the element to 'value'. Did you interact with the correct element?

3 Answers

Not sure why you have the props.getProporty in there or what you trying to do with that, you can just use the xpath right in the driver.findElement()

driver.findElement(By.xpath("//android.widget.EditText[@text='Mobile']")).sendKeys("123456");

In UIAutomator2 mode, if the element is not an editText, can‘t use sendKeys()/setValue()
Can user driver.pressKey(KeyEvent(AndroidKey.A)) instead

The field you are trying to access should be of editText to accept input keys. if you are getting parent element of the editText, there is a chance that you are trying to sendKeys to a layout field than actual element. Inspect the element retrieved in the Appium Desktop session

Related