Home » Software Testing » Automation Testing » Selenium WebDriver Tutorial » Implicit Wait in Selenium WebDriver

Implicit Wait in Selenium WebDriver

Implicit wait in Selenium WebDriver introduction:

Implicit wait in WebDriver has solved many issues that occurs due to intensive use of Ajax in any webpage. Ajax intends loading time of each element on webpage to vary.Due to different loading time, it become cumbersome to find all element on web page as soon as web page opens and this causes your script to fail.
Implicit wait specifies the amount of time the driver should wait when searching for an element if it is not immediately present. So to search any element on webpage driver will poll the page till the time it does not found element or time out expires and then it throws exception like “NoSuchElementException”.

Watch video to know more about facts of Implicit Wait

Few important points about Implicit wait:
Implicit wait is called global wait because once it is declared it stay with WebDriver instance for its life time.
2- It comes in to action, as soon as it sees any driver.findElement/driver.findElements statement in code. it means it will wait for all the statements made to find WebElement on webpage.
3- Default wait is “0” that can be custom as per our need depending upon network latency.
4- Implicit wait should be avoided with slow locator like xpath due to its adverse impact on script run time.
Before moving ahead why not we see code snippet taken from WebDriver api which have all the code of TimeOut interface

As we can see in above code that implicitlyWait take two parameters, First parameter takes the time for which driver instance have to wait and second instance is an enum TimeUnit which have constants like Seconds, Minutes, Hours, Days,milliSeconds, micoSeconds and nanoSeconds.
So if someone has taken 5 as time to wait and TimeUnit.SECONDS then it means driver instance will wait for next 5 seconds before throwing exceptions if element is not found on webpage.
code snippet used for implicitlyWait

above line of code should be used just after driver instance is initialise.
So lets take one example of implicit wait.

1- Open bing website
2- Enter Selenium Tutorials string in search text field
3- Once string will be entered in textfield, some ajax drop down will appear and in this first choice should be selected.

Description of above code:
above code will open one firefox instance and will open bing.com and after opening bing.com it will enter Selenium Tutorials string in search box but as soon as we will enter string ajax dropdown will not appear on screen and for this we need to wait for 2-3 seconds so for safer side, have used 5 second in code and after 5 second elapsed code will perform the action of selecting the first dropdown option.

4 thoughts on “Implicit Wait in Selenium WebDriver”

  1. Pingback: Check if an element exists using WebDriver | Abode QA

  2. Pingback: WebDriver’s most popular Commands | Abode QA

  3. Pingback: Handling Multiple Windows in WebDriver | Abode QA

  4. Pingback: Check if an element exists using WebDriver | Abode QA

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top
Scroll to Top