How to use Implicit wait in Selenium Webdriver

This guide will help you to understand implicit wait in Selenium Webdriver and implementation as well. If you have ever worked on any automation tool then you must be aware of Sync issues in the script.

It is one of biggest pain for an automation engineer to handle sync issue between elements.

Sometimes an application will not able to load elements due to below issues.

  • Network issue
  • Application issues
  • Browser stopping JavaScript call.

And so on.

By default, Selenium will not wait for an element once page load completes. It checks for an element on the page then it performs some operation based on your script but if the element is not present then it throws NoSuchElement Exception.

 

This is one of the interview questions that what is the default timeout in Selenium is.

Answer- Default timeout is ZERO.

 

I have listed down some most frequent exception of Selenium. Hope it will help you.

Frequently faced exception is Selenium Webdriver

 

If you are not sure how to handle exception then below post will help you.

How to handle exception in Selenium Webdriver

 

Our main intention to use Implicit wait in selenium is to instruct Webdriver that wait for a specific amount before throwing an exception.

I will highly recommend using implicit wait in your every selenium script.

Note- Implicit wait in selenium webdriver will be applicable throughout your script and will works on all element in the script once your specified implicit wait.

 

 

Syntax of Implicit wait in selenium webdriver

 

Here in above example I have used TimeUnit as seconds but you have so many options to use

Seconds, Minutes, Days, Hours, Microsecond, Milliseconds and so on check below screenshot for more information.

 

Implicit wait in Selenium

 

 

Once you move forward, you will get to know some more Timeout in Selenium like

Page load timeout in Selenium

Script load timeout in Selenium

Implicit wait in selenium Webdriver

Explicit wait in Selenium

Fluent wait in Selenium

Do not confuse with these exceptions because each of this having different usage.

I will cover all timeout with separate example

 

Complete program with usage of implicit wait in selenium webdriver

 

Console- Above script will fail because no login id is present on the page but it will wait for max 30 second before throwing an exception.

 

implicit wait in Selenium webdriver

Note- This is the max time so if any element is coming before 30 seconds it will move to next element.

Please comment below if any issues or any feedback 🙂

 

12 Comments

  1. Debanjan Bhattacharjee
  2. Raja
  3. pooja
  4. sudhr
  5. sudhr