我正在使用appium实现应用程序的自动化。我可以用午餐吃应用程序,但我要登录,它可以读取XPath进行登录。但appium无法输入手机号码。对于移动设备,我正在使用模拟器。
这是我的代码:
driver.findElement(By.xpath(props.getProperty("mobile"))).sendKeys("123456");
这是我的Xpath:
mobile=//android.widget.EditText[@text='Mobile']
错误面对:
运行命令io.appium.uiautomator2.common.exceptions.InvalidElementStateException时遇到内部错误:无法将元素设置为"value"。你与正确的元素互动了吗?不确定为什么要在props.getProporty
中,也不确定要用它做什么,可以直接在driver.findElement()
中使用xpath
driver.findElement(By.xpath("//android.widget.EditText[@text='Mobile']")).sendKeys("123456");
在UIAutomator2模式中,如果元素不是editText,则不能使用sendKeys()/setValue()
可以使用driver.pressKey(KeyEvent(AndroidKey.A))
代替
您试图访问的字段应该是editText,以接受输入键。若您获取的是editText的父元素,则有可能您试图将Keys发送到布局字段而不是实际元素。检查Appium Desktop会话中检索到的元素