I am automating an "Add Employee" form-based test for our production site. When an id is entered, or an email , or a name, that already exists, then, a service error is popped up that shows the employee cannot be registered. Even though this box comes up, the test passes :(. I tried using the driver.switchTo().alert() function in my code. This is what happened:
A lot of times what happens is the Selenium code executes before the browser renders the alert. What I tend to do is something like this:
Alert getAlert() {
try {
Alert alert = driver.switchTo().alert();
return alert;
} catch (NoAlertPresentException e) {
// no alert to dismiss, so return null
return null;
}
}
I don't really think this is ideal, but I don't know of a better way in Selenium at the moment. I tend to just call this blindly from my tests at regular intervals, and if it returns an alert, I'll just dismiss it. If you are expecting an alert from your app and want to dismiss it before proceeding, wrap it in a while loop.
http://stackoverflow.com/questions/1176348/access-to-file-download-dialog-in-firefox
A lot of times what happens is the Selenium code executes before the browser renders the alert. What I tend to do is something like this:
Alert getAlert() {
try {
Alert alert = driver.switchTo().alert();
return alert;
} catch (NoAlertPresentException e) {
// no alert to dismiss, so return null
return null;
}
}
I don't really think this is ideal, but I don't know of a better way in Selenium at the moment. I tend to just call this blindly from my tests at regular intervals, and if it returns an alert, I'll just dismiss it. If you are expecting an alert from your app and want to dismiss it before proceeding, wrap it in a while loop.
http://stackoverflow.com/questions/1176348/access-to-file-download-dialog-in-firefox