等到满足条件 Selenium-Webdriver
Wait until condition is met Selenium-Webdriver
我正在尝试在硒网络驱动程序条件之上创建其他条件。我仍在努力掌握承诺和回调的完整概念。由于堆栈溢出的帮助,我得到了极大的改善。我不确定如何在 javascript 中每隔几秒钟重复一个条件。我的遗产也可能是错误的。
var WebElementCondition = require('./selenium-webdriver/lib/until');
var ExpectedConditions = function()
{
this.waitForWindowWithTitle = function (title)
{
return driver.getAllWindowHandles().then(function (title, handles) {
console.log(handles.length + ' .then function');
for (var window in handles) {
if (window.title === title)
{
return true;
}
else
{
return false;
}
}
});
}
}
module.exports = ExpectedConditions;
require('util').inherits(module.exports, WebElementCondition);
在等待窗口与标题函数中,我会做类似的事情
吗return driver.wait(10000).then(function() {
driver.getAllWindowHandles().then(function (title, handles) {
console.log(handles.length + ' .then function');
for (var window in handles) {
if (window.title === title)
{
return true;
}
else
{
return false;
}
}
});
});
您可以使用接受任何JS函数的wait
来创建自定义条件。下面是一个检查角度何时准备就绪的示例。
// Wait for Angular to Finish
function angularReady(): any {
return $browser.executeScript("return (window.angular !== undefined) && (angular.element(document).injector() !== undefined) && (angular.element(document).injector().get('$http').pendingRequests.length === 0)")
.then(function(angularIsReady) {
return angularIsReady === true;
});
}
$browser.wait(angularReady, 5000).then(...);
等待类型定义
wait<T>(condition: promise.Promise<T> | until.Condition<T> | ((driver: WebDriver) => T) | Function, timeout?: number, opt_message?: string): promise.Promise<T>;
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- WebDriverException:tinyMCE未在selenium Web driver java中定义
- python-selenium-点击上升链接
- Selenium Web驱动程序和javascript
- Selenium WebDriver and JavaScript change
- Selenium驱动程序不反映单击()后的页面更改
- Selenium无法在浏览器DOM中定位元素
- 无法使用Selenium创建本地windows目录结构
- Xpath对Selenium Web驱动程序无效”;Xpath未找到”;
- 运行Selenium Webdriver Test时,不会出现警报
- Selenium RemoteWebDriver中的批处理/原子操作
- 比较Selenium IDE中的日期
- 在selenium python中执行脚本
- Selenium+js:匹配日期'dd Mmmm-yyyy'在字符串中
- 适用于多种浏览器的Selenium-需要能够执行javascript的webDriver
- 等待,直到使用Java在selenium网络驱动程序中手动单击登录按钮
- 如何从Selenium获取JavaScript值
- Sencha禁用按钮和Selenium Web驱动程序
- 如何使用selenium和同步JS进行屏幕截图
- 如何在一个网页的文本框中输入文本与onblur,onfocus和onkeydown属性使用Selenium Webdri