【问题标题】:Error getting on Appium, Cannot set the element to 'value'. Did you interact with the correct element?上 Appium 时出错,无法将元素设置为“值”。您是否与正确的元素交互?
【发布时间】:2021-05-03 12:13:43
【问题描述】:

我正在使用 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:无法将元素设置为“值”。您是否与正确的元素交互?

【问题讨论】:

  • 可能是该字段有一些特殊的输入验证器,这会阻止 sendKeys 方法在其上正常工作。尝试通过操作 1 或移动设备发送文本:类型(后者仅在 v. 1.17 或 appium@beta 中可用)

标签: android-emulator appium-android


【解决方案1】:

不知道为什么你有props.getProporty 或者你想用它做什么,你可以直接在driver.findElement() 中使用xpath

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

【讨论】:

  • 用 props.getProperty 没问题。我的问题是我的模拟器无法读取 sendKeys 值。
  • 在执行sendkeys 命令之前,您是否在元素上使用了click()?
  • 此问题已修复。我通过操作发送了文本。
【解决方案2】:

在UIAutomator2模式下,如果元素不是editText,则不能使用sendKeys()/setValue()
可以改用driver.pressKey(KeyEvent(AndroidKey.A))吗

【讨论】:

    【解决方案3】:

    您尝试访问的字段应该是 editText 以接受输入键。如果您正在获取editText 的父元素,那么您可能会尝试将Keys 发送到布局字段而不是实际元素。检查在 Appium 桌面会话中检索到的元素

    【讨论】:

      猜你喜欢
      • 2019-03-17
      • 2021-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-17
      • 2018-07-09
      • 1970-01-01
      相关资源
      最近更新 更多