Selenium is a test automation suite with different components to test web based applications. Of the many components, Selenium Webdriver is the latest addition to the suite which made communication directly with the browser possible and thus reduced the time needed for executing tests. Selenium webdriver has many other advantages which make it highly user friendly and one of them is Selenium Webdriver Waits. Selenium webdriver provides different types of waits and this article discuss about them in detail.
Selenium WebDriver Waits
Waits are mainly used to troubleshoot the problems faced while redirecting to different web pages. Troubleshooting will be done by refreshing all web pages and by reloading the new web elements. Webdriver offers two different types of waits for the users and they are “Implicit Wait” and “Explicit Wait”.
Implicit waits are generally used to give a default waiting time in between test steps or commands throughout the test so that one step or command will be executed only after that specific period of time after the completion of the previous step or command. Implicit wait can be declared in the setup method as it is a single line of a code. Both the syntax and approach of implicit wait is simpler when compared with explicit wait hence it is more transparent and less complicated.
There are some disadvantages also for implicit wait as it enhances the time to complete the test as there is a wait in between each step of command. In order to overcome this issue, explicit wai has been developed in webdriver where the wait can be applied explicitly whenever required.
One needs to import java.util.concurrent.TimeUnit for accessing and applying implicit wait in the test script.
Syntax: drv.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Including the above line of code into the script is all what we should do to set an implicit wait. It is necessary to provide two values as parameters. One is the time needed to be waited between the steps in digit and its unit.
When you use explicit wait, an application can be put to wait till a specific condition is met or till the maximum time limit has expired. Explicit are applied only for specific instances. Classes such as webdriver wait and expected conditions are introduced by the webdriver to implement explicit waits into the test scripts. However, you need to import the below given packages before script creation.