Using implicit wait in selenium

ImplicitWait

ImplicitWait as per the Java Docs is to specify the amount of time the WebDriver instance i.e. the driver should wait when searching for an element if it is not immediately present in the HTML DOM in-terms of NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS or DAYS when trying to find an element or elements if they are not immediately available. The default setting is 0 which means the driver when finds an instruction to find an element or elements, the search starts and results are available on immediate basis.

In this case, after a fresh loading of a Webpage an element or elements may be / may not be found on an immediate search. So your Automation Framework may be facing any of these exceptions:

Hence we introduce ImplicitWait. By inducing ImplicitWait the driver will poll the DOM Tree until the element has been found for the configured amount of time looking out for the element or elements before throwing a NoSuchElementException. By that time the element or elements for which you had been looking for may be available in the HTML DOM. As in your code you have already set ImplicitWait to a value of 10 seconds, the driver will poll the HTML DOM for 10 seconds.

  • Python:

    driver.implicitly_wait(10)
    
  • Java:

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

    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
    

Finally, once you set the ImplicitWait, the WebDriver instance i.e. the driver is able to carry this configuration till its lifetime. But if you need to change the coarse of time for the WebDriver instance i.e. the driver to wait then you can reconfigure it as follows:

  • Python:

    driver.implicitly_wait(5)
    
  • Java:

    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    
  • DotNet:

    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
    

If at any point of time you want to nullify the ImplicitWait you can reconfigure it as follows:

  • Python:

    driver.implicitly_wait(0)
    
  • Java:

    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    
  • DotNet:

    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);
    

Answering your questions

  • …Wait for the URL… : No, ImplicitWait have no effect on page loading.
  • …For finding the element… : Yes, ImplicitWait will define the coarse of time the WebDriver instance will wait looking out for the element or elements.
  • …Implicit wait once… : Yes, you need to configure ImplicitWait only once and it is applicable throughout the lifetime of the WebDriver instance.
  • …Every element search… : Yes, applicable when ever findElement() or findElements() is invoked.

Leave a Comment