Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Selenium by (7k points)

I want to check the existence of an alert in WebDriver.

Sometimes it pops and will not pop up sometimes. I want to check if the alert exists first and proceed

1 Answer

0 votes
by (31.9k points)
edited by

The following code allows you to determine if there is an alert without exceptions and without creating the WebDriverWait object.

boolean isDialogPresent(WebDriver driver) {

    IAlert alert = ExpectedConditions.AlertIsPresent().Invoke(driver);

    return (alert != null);

}

Want to learn Selenium, check out our Selenium training.

Learn Selenium automation testing with our comprehensive Selenium Tutorial and ace your next job interview with our Selenium Interview Questions!

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...