Reputation: 1315
I have tests that involve required fields and alert boxes. When you don't fill out the required field, an alert box should display. I am checking for this alert box by using
ExpectedConditions.alertIsPresent()
When I fill out the required field, I want to verify that an alert no longer appears. How can I do this using Selenium and Java?
Upvotes: 1
Views: 2277
Reputation: 268
in case of webdriver
public boolean isAlertPresent(){
try{
driver.switchTo().alert();
return true;
}catch (NoAlertPresentException e){
return false;
}
}
Upvotes: 1
Reputation: 3776
Use the following code snippet
public boolean isAlertPresent() {
try {
new WebDriverWait(driver,10).untill(ExpectedConditions.alertIsPresent);
return true;
} catch (TimeOutException e) [
return false;
}
}
Upvotes: 0