Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait for an alert in Selenium webdriver ? [duplicate]

Possible Duplicate:
selenium 2.4.0, how to check for presence of an alert

I am using the following code to close the alert window :

Alert alert3 = driver.switchTo().alert();
alert3.dismiss();

The alert appears a few seconds after the opening of the main window.

How can I wait and check if alert appears ?

like image 791
khris Avatar asked Sep 28 '12 11:09

khris


1 Answers

No default method for waiting for alert.

but, you can write your own method something like this.

waitForAlert(WebDriver driver)
{
   int i=0;
   while(i++<5)
   {
        try
        {
            Alert alert = driver.switchTo().alert();
            break;
        }
        catch(NoAlertPresentException e)
        {
          Thread.sleep(1000);
          continue;
        }
   }
}
like image 119
Santoshsarma Avatar answered Oct 08 '22 21:10

Santoshsarma