Different types of Selenium WebDriver Waits:
Waits helps the user to solve the issues which comes while redirecting to different web pages, by refreshing the web page and reloading the new web elements. At times there can be Ajax calls as well. So, a time delay occurs while reloading the web pages and reflecting the web elements.
WebDriver provides two types of waits to handle the loading of reappearing page & web element, windows appearance, pop ups and error messages and display of web elements on the web page:
- Implicit Wait
- Explicit Wait
1. WebDriver Implicit Wait:
Implicit waits are utilize to provide a default waiting time into each following test step/command over the complete test script. So, the next test step will be performed when the 30 seconds have passed after the previous test step.
- It is a single line code. It can be declared in the setup method of the test script.
- Its syntax and approach is simpler.
It is easy and simple to apply but it has some drawbacks as well. It increases the test script execution time as each command will stop to wait for a specified time before restart the execution.
import java.util.concurrent.TimeUnit – We have to import this package before applying the implicit wait.
2. WebDriver Explicit Wait:
It is used to stop the execution until the time for a particular condition is met or the maximum time has passed. Also, it is only applied for a particular case.
WebDriver has two classes to apply the Explicit waits into the test scripts:
We have to import this package before applying the explicit wait: