2
votes

I'm using PHP Webdriver for my tests. In one of my tests, an alert:

To display this page, Firefox must send information that will repeat any action (such as a search or other confirmation) that was performed earlier

is expected to appear.

How can I instruct the Webdriver to wait until the alert is present? for example - maximum wait timeout let's say 60 seconds, if the alert appears after 15 seconds, I want the Webdriver to let me know it that it exists.

screenshot of the alert enter image description here

1

1 Answers

2
votes

PHP version (look for syntax errors as I am not familiar with PHP):

// wait for at most 60s for the alert
// sleep for 500ms and retries if it the alert is present.
// return alert if present, otherwise null
$driver->wait(60, 500)->until(
  WebDriverExpectedCondition::alertIsPresent()
);

Note: 60 seconds, 500 ms are configurable based on your needs.

References:

  1. https://github.com/facebook/php-webdriver/wiki/HowTo-Wait
  2. https://facebook.github.io/php-webdriver/classes/WebDriverExpectedCondition.html#method_alertIsPresent

Java version:

WebDriverWait wait = new WebDriverWait(driver, 60); //60 seconds- configurable
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.accept();