ImplicitWait: A Placebo Pill just so that you can sleep well at night

ImplicitWait is a way to tell webdriver to wait for certain amount of time if the element is not immediately present in DOM. ImplicitWait policy applies to all the elements, for the life of the Web Driver object instance.

It is a normal practice to declare this Wait policy right after the page is loaded:

//Wait for at most 15 seconds if any element is not immediately found:
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

When searching for a single element, the driver should poll the page until the element has been found, or this timeout expires before throwing a NoSuchElementException. When searching for multiple elements, the driver should poll the page until at least one element has been found or this timeout has expired.

The default setting for implicit wait is 0, i.e no wait. Once set, the implicit wait is set for the life of the Web Driver object instance until it changed again, and this applies to all element-locating using Find Element and Find Elements.

How frequently does implicitWait poll the page?
The poll time is very specific to the driver implementation.

Implicit waits are in most cases implemented in ‘remote’ side of WebDriver, i.e. they are baked into IEDriverServer.exe, chromedriver.exe, the WebDriver Firefox extension that gets installed into the anonymous Firefox profile, and the Java remote WebDriver server (selenium-server-standalone.jar).Thus the poll time depends upon the specific driver’s implementation.

Something worth mentioning: implicit wait checks the presence of the element in DOM, not whether or not it is displayed on the page yet. An element could be existing in the DOM, but not visible yet. So applying implicitWait will reduce the chances NoSuchElementException is thrown out of our script, but not necessarily guarantee a safe interaction.

So implicitWait is a placebo Wait. You put it in your code to get a sense of safe and security while you are sleeping at night. But really, it doesn’t guarantee anything.

When shall we use ImplicitWait?
When the page is first loaded.

Q&A: ImplicitWait Breakdown:

  • What we are waiting for?
    WebElement or a list of WebElements
  • How long do we wait at most?
    It is defined in timeout parameter
  • How frequently we check the result?
    Depends upon the specific webdriver implementation
  • What we are checking?
    To see it is in DOM yet
  • What to do if on show at the end?
    Throws NoSuchElementException

Q&A:When to use it?

  • Pro?
    Once set, applies to all
  • Con?
    Cause a lot of complications when it is mixed with explicit wait.
  • When to use?
    If you are a beginner in Automation, put it in your code when the page is first loaded.
    But not recommended if you know what you are doing.
  • One thought on “ImplicitWait: A Placebo Pill just so that you can sleep well at night

    1. I was looking out for more info on Gmail and came across

      I would just like to say thanks to you for your help and advice in this informative article.

      I am also working on a gmail guide at this time.

    Leave a Reply

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