【问题标题】:Selenium Node API web driver wait timeout handlerSelenium Node API Web 驱动程序等待超时处理程序
【发布时间】:2016-02-29 20:16:33
【问题描述】:

我是 Selenium 网络驱动器的新手。尝试做一些页面自动化,并使用driver.wait 函数先等待选择器呈现,然后再做一些操作。

想知道如果元素在 x 秒后没有显示,Selenium 是否有办法传入超时处理程序来管理超时。

这是我的代码:

driver.wait(function () {
    return driver.isElementPresent(webdriver.By.css('input[id="searchMap"]'));
}, 10000);

所以 10 秒后如果 input[id="searchMap"] 没有出现,Selenium 脚本将结束并抛出错误。

我正在寻找这样的东西:

driver.wait(function () {
    return driver.isElementPresent(webdriver.By.css('input[id="searchMap"]'));
}, 10000, function fail(){
    console.log("Time is up!");
});

【问题讨论】:

标签: selenium selenium-webdriver timeout


【解决方案1】:

自己找到了解决方案。对于 Selenium promise 类,必须使用 catch

http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/promise_exports_Promise.html

这是我的代码:

driver.wait(function () {
    return driver.isElementPresent(webdriver.By.css('div.info-page'));
}, 10000).catch(function(e){
    console.log('Catching Error');
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    • 2018-04-24
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2022-01-28
    相关资源
    最近更新 更多