Delivered by FeedBurner

How to use implicit wait in selenium webdriver and why

There are 2 types of waits available in Webdriver/Selenium 2 software testing tool. One of them is Implicit wait and another one is explicit wait. Both (Implicit wait and explicit wait) are useful for waiting in WebDriver. Using waits, we are telling WebDriver to wait for a certain amount of time before going to next step. We will see about explicit wait in my upcoming posts. In this post let me tell you why and how to use implicit wait in webdriver.

Why Need Implicit Wait In WebDriver
As you knows sometimes, some elements takes some time to appear on software web application page when browser is loading the page. In this case, sometime your webdriver test will fail if you have not applied Implicit wait in your test case. If implicit wait is applied in your test case then webdriver will wait for specified amount of time if targeted element not appears on page. As you know, we can Set default timeout or use "setTimeout" command in selenium IDE which is same as implicit wait in webdriver.

If you write implicit wait statement in you webdriver software testing script then it will be applied automatically to all elements of your test case. I am suggesting you to use Implicit wait in your all test script of software web application with 10 to 15 seconds. In webdriver, Implicit wait statement is as bellow.

How To Write Implicit Wait In WebDriver
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

Above statement will tell webdriver to wait for 15 seconds if targeted element not found/not appears on page. Le we look at simple example to understand implicit wait better.

Copy bellow given @Test method part and replace it with the @Test method part of example given on this page(Note : @Test method is marked with pink color in that example).

 public void test () 
   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
   driver.findElement(By.xpath("//input[@name='fname']")).sendKeys("My Name");

In Above webdriver test case with JUnit example,  1st Element 'xpath("//input[@name='fname']")' will be found on page but element xpath("//input[@name='namexyz']") is not there on page. So in this case webdriver will wait for 15 to locate that element on page because we have written implicit wait statement in our code. At last webdriver test will fail because xpath("//input[@name='namexyz']") is not on the page.


  1. I have a doubt. If i put implicit wait for 30 seconds and then if webdriver searches at the first time and if element not present then will it wait for total 30 seconds and then search for the second time or it will look for it immediately at 10 or 15 second if the element appears??

    if someone answers this it would be great help. Thanks!

    1. in implicit wait, if webdriver cannot find webelement in starting, it will wait for specified time duration. Webdriver will not search during this wait interval. Once specified time is over, it will try to search again for last time before throwing any exception.
      In Fluent wait and explicit wait, if wait time is 30 seconds, webdriver tries to search for element after some specified time say 500 miliseconds

  2. Do we have to mention implicit wait once in a script or where ever we Thread. Sleep.pls answer
    Thanks in advance

    1. You have to write only once in script.