How to check if an alert is open using nodejs webdriver (wd) How to check if an alert is open using nodejs webdriver (wd) selenium selenium

How to check if an alert is open using nodejs webdriver (wd)


This 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;