13

I was reading up on implicit and explicit waits and found the following two statements:

Implicit wait is not considered a good practice because different browsers have different loading times and implicit wait will cause different results in different browsers.

I have tried to find the blog where I read this, but couldn't find it. But, a similar view is expressed in this article.

Next quote is from here:

When compared to Explicit wait, Implicit wait is transparent and uncomplicated. The syntax and approach is simpler than explicit wait. Being easy and simple to apply, implicit wait introduces a few drawbacks as well. It gives rise to the test script execution time as each of the command would be ceased to wait for a stipulated amount of time before resuming the execution.

Question: Is it a bad practice to use implicit wait? Should one use only explicit wait?

Note: From the Selenium Documentation, it is clear that one should not use both the waits together. I am asking only about implicit wait.

3 Answers 3

13

Short answer: Yes it is a bad practise, unless you have a very very very good reason, do not use implicit wait.

This Stack Overflow answers really puts the difference in great detail. (read this!)

I once had someone on my team who thought it was a good idea, until I started researching why all our tests had such a long starting time. Somewhere in our setup the implicit wait was increased to some seconds, causing every test start to be seconds slower and even longer to run. We checked the loading indicator was not there, leading to use the full implicit wait time.

if checking for absence of element must always wait until timeout.

Maybe in some situations its handy to add a couple of (milli)seconds for each search, incase you want to find similar elements and you know you have to wait a X period. Increase the implicit wait for some steps and then set it back to 0, never just increase it for the whole run.

FluentWait

If you think the syntax of the explicit wait is to verbose, have a look at this FluentWait example. Put this function somewhere and use it to find elements that you need to wait for.

5
  • Just a silly question though. If the use of findElement is discouraged, one always has to use a variant of wait.Until(ExpectedCondition...)?
    – FDM
    Apr 9, 2015 at 9:52
  • @FDM Where is findElement discouraged? If you know the element is there why would you want to wait? Apr 9, 2015 at 9:55
  • The first link you posted: it says implicit waiting only occurs in findElement methods. Since you're never sure how fast a page will load, you're thus always waiting implicitly.
    – FDM
    Apr 9, 2015 at 10:07
  • I would wait for the first used element on a page or another indicator that the page is ready loading/drawing, we added a isReady() function to our JS framework to check if the page was fully loaded in somecases. From that moment you should be able to know which elements exist or not. Apr 9, 2015 at 10:50
  • What if something changes on the page?
    – fijiaaron
    Feb 10, 2017 at 22:27
1

Usage of Waits in selenium should be chosen judiciously based on the scenario and the applications you are automating.

If you use the implicit wait in selenium it applies to the web driver globally and increases the execution time for the entire script. so it is not always advisable.

Whereas you can use the explicit wait when ever you know that the loading of a particular element takes some time or want the page to load in case similar to this explicit wait will be preferred.

-1

In case of implicit wait driver will take defined time to move to next step irrespective of element found or not found but in case of explicit wait driver will move to next step once element found/condition met and driver will not wait for defined wait time. So we can say that in case of explicit wait, wait time is 0-time given but in case of implicit it is constant. Answer is -Explicit wait time is time saving.

1
  • How does this improve on the accepted answer?
    – Kate Paulk
    Mar 16, 2018 at 15:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.