What is Implicit wait? How to Achieve Implicit wait in Selenium?

What is Implicit wait in Selenium WebDriver?

It means that we can tell Selenium that we would like it to wait for a certain amount of time before throwing an exception (when it cannot find the element on the page).

synchronization in selenium webdriver - Implicit wait

For example:

driver.manage().timeouts().pageLoadTimeout(50,TimeUnit.SECONDS);
 
Above statement will set the navigation timeout as 50. This means that selenium script will wait for maximum 50 seconds for page to load. If page does not load within 50 seconds, it will throw an exception.
The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.
Syntax:
 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command.

Logic: – Selenium checks the control in first go, in case it is not able to find the control it will wait for the given implicit time, and then try again, after the end of the wait time to look for the control before throwing an exception. By default, its value is 0.

Limitation: – implicit wait will be applied to all the elements of the test case by default.

Key Notes

  • Implicit wait is a single line of a code and can be declared in the setup method of the test script.
  • When compared to Explicit wait, Implicit wait is transparent and uncomplicated. The syntax and approach is simpler than explicit wait.
  • Implicit wait will not work all the commands/statements in the application. It will work only for “FindElement” and “FindElements” statements
Being easy and simple to apply, implicit wait introduces a few drawbacks as well. It gives rise to the test script execution time as each of the command would be ceased to wait for a stipulated amount of time before resuming the execution.
Thus, in order to trouble shoot this issue, WebDriver introduces Explicit waits where we can explicitly apply waits whenever the situation arises instead of forcefully waiting while executing each of the test steps.

Example for Implicit Wait

WebDriver driver = new FirefoxDiriver();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get(“http://www.google.com”);

 

Refer below video –

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

https://www.youtube.com/automationtalks

Get the Framework code at Github Repo: https://github.com/prakashnarkhede?tab=repositories