【问题标题】:Webdriverio TypeError: element.click is not a functionWebdriverio TypeError:element.click 不是函数
【发布时间】:2019-05-21 01:31:40
【问题描述】:
async function t(e){
    return e;
}

async getByResourceId(id, wait= 5000){
        const elm = this.driver.$('android=new UiSelector().resourceId("'+id+'")');
        const telm = await t(elm);
}

我正在尝试使用 appium 和 webdriverio 自动化一个 android 应用程序,但我遇到了一个非常奇怪的错误。我使用 webdriver 的 $ 函数(它也发生在 element 函数中)来定位一个元素,然后我将它传递给函数 t。当我把它拿回来时,它是一个不同的 obj。

我尝试在 getByResourceId 的第一行和第二行之间添加延迟,以确保它不是计时错误:

async getByResourceId(id, wait= 5000){
            const elm = this.driver.$('android=new UiSelector().resourceId("'+id+'")');
            await _setTimeout(5000);
            //elm still OK (aka elm.click works)
            const telm = await t(elm);
            //telm is broken (aka getting TypeError: telm.click is not a function)
        }

那没用。破坏榆树的事情是不返回承诺。有没有人知道如何让它发挥作用?

编辑:我发现这个https://stackoverflow.com/a/47176108/10816010 很有帮助。显然我必须使用同步方法(使用 WDIO 测试运行程序)并让 WDIO 测试运行程序控制同步而不是使用异步等待来获得我想要的功能。

编辑 2:这与第 5 版 webdriverio 无关

【问题讨论】:

  • 嘿吉拉德!好吧,很高兴您找到了解决问题的方法。您没有使用sync: true 标志,在您的场景中,问题接缝是您点击ELEMENT 对象(telm 值),这当然会触发telm.click is not a function TypeError。我会在 const telm = await t(elm); 语句之后放置一个 browser.debug() 并使用结果单击元素( hint, hint! :) )。干杯!

标签: node.js webdriver-io


【解决方案1】:

假设您像这样启动驱动程序:

const driver = await remote({
   port: 4723,
   logLevel: 'debug',
   desiredCapabilities: {
     // your caps here
   }
})

你可以使用async-retry:

async getByResourceId(id, wait=5000){
  return await retry(async bail => {
    const el = await driver.element(`android=new UiSelector().resourceId("${id}")`)
    return el;
  }, {
    retries: 3,
    minTimeout: wait,
    driver: driver
  })
}

您可以查看 wdio 示例here

【讨论】:

猜你喜欢
  • 2022-10-24
  • 1970-01-01
  • 2021-07-29
  • 2019-08-24
  • 1970-01-01
  • 2022-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多