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(){});
}