I am using a Chrome Driver and trying to test a webpage.
Normally it runs fine, but sometimes I get exceptions:
org.openqa.selenium.UnhandledAlertE
Following is working for me
private void acceptSecurityAlert() {
Wait wait = new FluentWait(driver).withTimeout(10, TimeUnit.SECONDS)
.pollingEvery(3, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
Alert alert = wait.until(new Function() {
public Alert apply(WebDriver driver) {
try {
return driver.switchTo().alert();
} catch(NoAlertPresentException e) {
return null;
}
}
});
alert.accept();
}