admin管理员组文章数量:1323318
I am struggling writing a test; in which I want to check if an alert exists, check its text if it does and accept it.
I checked How to wait for an alert in Selenium webdriver ?, How to check if an alert exists using WebDriver? and selenium 2.4.0, how to check for presence of an alert, but I fail to adapt it using
I have written something along
browser.alertText(function (err, text) {
if (text) {
browser.acceptAlert(function () {
// ...
});
}
});
It works tremendously well when an alert is displayed, but alertText
hangs when there is no alert window.
How can I check if the alert exists before issuing alertText
?
Thanks for your help,
I am struggling writing a test; in which I want to check if an alert exists, check its text if it does and accept it.
I checked How to wait for an alert in Selenium webdriver ?, How to check if an alert exists using WebDriver? and selenium 2.4.0, how to check for presence of an alert, but I fail to adapt it using https://github./admc/wd
I have written something along
browser.alertText(function (err, text) {
if (text) {
browser.acceptAlert(function () {
// ...
});
}
});
It works tremendously well when an alert is displayed, but alertText
hangs when there is no alert window.
How can I check if the alert exists before issuing alertText
?
Thanks for your help,
Share edited May 23, 2017 at 12:22 CommunityBot 11 silver badge asked Jan 22, 2014 at 11:02 lkennethlkenneth 1312 silver badges8 bronze badges2 Answers
Reset to default 7This may help - this is how I detect an alert using Selenium Webdriver for node.js:
var webdriver = require('selenium-webdriver');
var url = "http://web-page-to-test-for-alert";
driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get(url);
driver.switchTo().alert().then(
function() {
console.log("alert detected");
},
function() {
console.log("no alert detected");
}
);
driver.quit();
'then' is related to promises: then(success, failure)
and this may also help - it's how I ignore any alert that presents on a page:
function ignoreAlert(driver) {
// detect and accept any alert
driver.switchTo().alert().then(function() {
driver.switchTo().alert().accept();},
function(){});
}
Make sure to set ignoreSynchronization if you're navigating to a non angular app:
browser.ignoreSynchronization = true;
browser.get(url);
browser.switchTo().alert().then(function() {
browser.switchTo().alert().accept();
}, function(){});
browser.ignoreSynchronization = false;
本文标签: javascriptHow to check if an alert is open using nodejs webdriver (wd)Stack Overflow
版权声明:本文标题:javascript - How to check if an alert is open using nodejs webdriver (wd) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742138473a2422475.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论