Skip to content
cprn edited this page Sep 16, 2016 · 3 revisions

Explicit Waits

An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. The worst case of this is sleep(), which sets the condition to an exact time period to wait. There are some convenience methods provided that help you write code that will wait only as long as required. WebDriverWait in combination with WebDriverExpectedCondition is one way this can be accomplished.

// wait for at most 10s for the page tile to be 'My Page'
// sleep for 500ms and retries if it the title is not correct.
$driver->wait(10, 500)->until(
  WebDriverExpectedCondition::titleIs('My Page')
);

Implicit Waits

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.

$driver->manage()->timeouts()->implicitlyWait(10);

Clone this wiki locally