WebDriver enables the user to choose among the available wait to handle situations where the execution flow may require a sleep for few seconds in order to load the web elements or meet the specific condition.
There are three types of wait are available in WebDriver
- Implicit waits are used to provide a default waiting time between each consecutive test step/command access the entire test script. Or once it is declared it will be available for the enter life of the WebDriver instance. In real world situation, every test steps/conditions do not need to wait, therefore implicit wait causes slow the process.
- Explicit Waits are used to halt the execution until the time a particular condition is meet or the maximum time has elapsed. Unlike implicit wait, explicit waits are applied for a particular instance only. (Explicit Wait + ExpectedCondition)
- Fluent wait, let’s say you have an element which sometime appears in 1 second and sometime it takes minutes to appear. In that case it is better to find element again and again until it find it or until the final timer runs out.
- Page Load Time Out
- Set Script Time Out
Some basic questions and answer from Test Automation School
- What does this WebDriver command do? manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS)
- Wait up to 5 seconds any time an element that it need to interact with is not really present.
- Which Selenium class allows you to do explicit waits?
- Explicit waits will always wait the entire time specified by the timeout.
- Which type of wait strategy allows you to specify the condition to wait for?
- Explicit Wait
- Which Selenium class is used to note the type of condition to wait for?
- To wait for an element to disappear, which method should be used?
- What happens if the element is still not found after waiting the specified amount of time?
- An Exception has been thrown
- Fluent waits allow you to ignore exceptions that may be thrown when polling for an element?
- Selenium provides a method to allow you to wait for the page to completely load.
- The purpose of the setScriptTimeout() method is to set the maximum amount of time it should take for the ________.