javascript - Webdriver.waitUntil 未按预期工作

标签 javascript node.js selenium selenium-webdriver webdriver-io

我正在使用 wedriverio 4.5:

./node_modules/.bin/wdio -v
v4.5.2

我需要等到某个元素存在,如果不存在则处理这种情况。

例如:

let element = browser.element('.unexisting');
browser.waitUntil(
        function () {
            return element.isExisting();
        },
        1000,
        'Element is not found.'
);

但是,如果页面上不存在元素,Webdriver 会将我的测试标记为失败并显示消息:“超时超过 10000 毫秒。”尝试减少运行时间或增加测试规范的超时( http://webdriver.io/guide/testrunner/timeouts.html );如果返回 Promise,请确保它能够解决。'

  1. 我该如何处理这种情况?

    • 我尝试了 try-catch block ,但无论如何我看到了有关超时和测试失败的相同消息。
    • 我尝试了 element.waitForExist() 但行为是相同的
    • 我尝试使用错误处理程序(但没有帮助)

    browser.on('错误', 函数(e) { console.log('处理浏览器错误'); })

  2. 为什么我看不到消息“未找到元素。”?

谢谢!

最佳答案

确保您的 waitForXXX 命令所花费的时间不会超过您的规范超时时间。如果它确实增加了您的规范超时,在您的情况下为 mochaOpts.timeout。在这里查看更多 http://webdriver.io/guide/testrunner/timeouts.html#Framework-related-timeouts

关于javascript - Webdriver.waitUntil 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42857529/

相关文章:

javascript - Backbone.js 将当前 URL 保存到历史记录中

python - 如何断言 python/selenium 中的特定元素不存在文本?

javascript拖放表格行

node.js - 没有服务器的 Angular 2 应用程序?

node.js - 使用node.js和mongodb时调用createIndex函数的位置、时间和次数

node.js - 发送电子邮件 sendgrid 在促销选项卡中收到,而不是在主要选项卡中

java - 在 Eclipse 中使用 Selenium 出现 JSONException

c# - 系统.NotImplementedException : performActions in selenium webdriver C#

javascript - angularjs 中的 $resource 无法正常工作

javascript - 正则表达式帮助从react/jsx元素中获取className