Monday 25 May 2015

How to check if alert pop up exists in selenium webdriver

You can use below code to check if Alert pop up (Modal Dialog) is open on the web page or not.

    try
    {
        driver.switchTo().alert();
     
      // Alert exists and we switched to it
    }
    catch (NoAlertPresentException exception)
    {
       
       //this block will be executed in case alert is not present
    }

You will need this code in scenario where you can not predict the presence of the Pop up Alert.

What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Buy Best Selenium Books

Contributors