【问题标题】:Cannot call setValue for element using Appium, Javascript and webdriverio无法使用 Appium、Javascript 和 webdriverio 为元素调用 setValue
【发布时间】:2021-10-30 03:24:35
【问题描述】:

我正在使用 Appium、UIAutomator2、webdriverio 和 JavaScript 来测试在虚拟设备上运行的应用程序。

我搜索一个元素并设置(或在本例中清除)它的值。

使用类选择器可以正常工作。

const codeField = await driver.$("android.widget.EditText");
await codeField.clearValue();

但我想通过 id 找到元素,所以我有这个:

const codeField = await driver.findElement("id", "de.abcdef.ghijkl:id/activation_code_input");
await codeField.clearValue();

结果:

webdriver: COMMAND findElement("id", "de.abcdef.ghijkl:id/activation_code_input")

webdriver: [POST] http://127.0.0.1:4723/wd/hub/session/f0a6844b-55e0-468d-b165-14cb219e55f7/element

webdriver: DATA {using: 'id', value: 'de.abcdef.ghijkl:id/activation_code_input'}

webdriver: RESULT {element-6066-11e4-a52e-4f735466cecf: '5d56ef1d-0036-4ecf-8b26-f060e290510b', ELEMENT: '5d56ef1d-0036-4ecf-8b26-f060e290510b'}

最后,什么时候应该设置字段的值

TypeError: codeField.clearValue is not a function

我错过了什么吗?

【问题讨论】:

    标签: webdriver-io appium-android


    【解决方案1】:

    由于某种原因,当我使用 findElement("id", ...) 或 findElement("xpath", ...) 时,webdriverio 无法正确解析检索到的元素。因为我想通过 id resp 来处理元素。 resource-id 而不是类,我可以通过使用 xpath 语法传递 resource-id 来解决它

    const codeField = await driver.$('//*[@resource-id="de.abcdef.ghijkl:id/activation_code_input"]');
    

    【讨论】:

      猜你喜欢
      • 2017-09-11
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      • 2019-12-19
      • 2020-04-02
      • 1970-01-01
      • 2018-03-15
      • 2019-03-10
      相关资源
      最近更新 更多