How to wait for an alert in Selenium webdriver ?
alert, java, selenium, selenium-webdriver
Solution
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;
}
}
}
Problem
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 ?