Last updated: Sep 22, 2019 17:34
Applied to the driver, usually set at the beginning of the test script, may be reset during the flow. Setting the wait period, tells the RWD client to continue searching for the element until it is found or the wait period ends. The following snippet shows how to set the Implicit Wait period.
Explicit Wait controls a specific verification operation and is implemented by the Selenium WebDriverWait class. When creating the class instance, supply the driver instance and the number of seconds to configure for the timeout. The waiting and repeated validations are performed in the driver server side (as opposed to the Implicit Wait, where the RWD client performs the repeated search function call).
The WebDriverWait class supports the until() method used to supply the validation condition. This method is usually used in conjunction with the ExpectedConditions class. The ExpectedConditions class provides static methods that can check for the following conditions of different UI Elements:
The following code sample creates an instance of the WebDriverWait class and then checks the visibility of a UI Element based on the element's Name. Note that if the condition is not met within the timeout (in this case 15 seconds) that the verification throws a TimeoutException.
The third type of wait supported by Selenium is Fluent Wait that extends the Explicit Wait to support more direct control over the frequency of the repeated verification calls.
The FluentWait class is a template class that supports setting the timeout, as well as two more important settings:
- pollingEvery - configures the interval at which the search action will be performed again.
- ignoring - configures a lit of Exception conditions ignored by the FluentWait
After the timeout period ends the FluentWait may throw a TimeoutException.
The following example shows a FluentWait instance that checks every 5 seconds, up to a 30 second timeout whether the element whose id is "Start" can be found on the screen.