How to wait for warnings in Selenium webdriver?

Possible duplicate:
selenium 2.4.0 how to check for an alert

I use the following code to close the warning window:

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

A warning appears a few seconds after opening the main window.

How can I wait and check if a warning appears?

+4
source share
2 answers

There is no default way to wait for a warning.

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; } } } 
+7
source
 public boolean isAlertPresent() { boolean presentFlag = false; try { // Check the presence of alert Alert alert = driver.switchTo().alert(); // Alert present; set the flag presentFlag = true; // if present consume the alert alert.accept(); } catch (NoAlertPresentException ex) { // Alert not present ex.printStackTrace(); } return presentFlag; } 
-1
source

Source: https://habr.com/ru/post/1436794/


All Articles