Make Selenium Easy

Are You Mixing Waits In Selenium WebDriver? – A Bad Practise

Last updated on July 11th, 2020 at 12:10 am

Selenium WebDriver provides two types of waits mechanisms:-

  1. Implicit Wait
  2. Explicit Wait – WebDriverWait and FluentWait

Implicit wait applies for a session of WebDriver and comes in to effect when WebDriver is trying to locate a web element or a list of web elements. Generally, we have a common practice of setting up implicit wait when we initialize a browser and use Explicit Wait wherever needed. But this we are doing wrong. We are mixing up waits which may end up with unexpected wait time.

There is no overriding of waits in Selenium WebDriver i.e. implicit wait will not override explicit wait or vice versa. In fact if you have both waits applied then both waits will be applicable in common scenarios.

Official website of Selenium also says the same:-

Warning: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example, setting an implicit wait of 10 seconds and an explicit wait of 15 seconds could cause a timeout to occur after 20 seconds.

Let’s see this behavior using some examples so that we can understand it better.

Using only implicit wait

In the below example, I will set an implicit wait and will try to locate a web element with wrong ID value.


It should throw NoSuchElementException after 30 seconds i.e. implicit wait timeout.

Using only Explicit Wait

I will set an explicit wait to locate a web element with a polling interval as 6 seconds.


Did you observe something strange? Explicit wait timeout was 20 seconds but actually it took 24 seconds. In console log, it appeared as 20 seconds only.

The reason behind is this is “Polling Interval”. We set it for 6 seconds. So WebDriver started locating element at 0th second, 6th Second, 12th seconds, and 18th second. Due to the polling interval as 6 seconds, next retry happened at 24th seconds where it observes that its timeout. In fact, timeout is checked just before it retries. This is the reason it took 24 seconds actually. You can increase the polling interval and understand it.

Hello Folks,

In last post we have seen the behavior of webdriver when mixing sleep with other waits.

In this post, we will learn behavior of webdriver when we mix implicit wait and explicit wait.

I hope, you will have good idea about implicit wait and explicit wait from my old posts.

We know when we define implicit wait , it is set for whole lifetime of webdriver while explicit wait is set for a particular step.

We will divide this topic in below scenarios:

  1. When element s found without any delay.
  2. When element is not found.

When element is found without any delay:

We will declare an implicit wait and explicit wait both in program.

Let’s see output of below program:

Wait starts:Sat Jul 01 13:14:46 IST 2017
Wait ends:Sat Jul 01 13:14:46 IST 2017

If you observe output, when element is found quickly, mixing of implicit wait and explicit wait will not impact on webdriver behavior.

 When element is not found:

This is the scenario where mixing of implicit and explicit wait changes webdriver behavior. We will see how but in three sub scenarios:

a. When implicit wait and explicit wait timeout are same.
b. When implicit wait time is greater than explicit wait time.
c. When explicit wait time is greater than implicit wait time.

 When implicit wait and explicit wait timeout are same:

I will keep implicit wait and explicit wait time same as 10 seconds. I will pass wrong locator so that webdriver will not be able to locate element. I will catch the exception to print wait ends time.

Output of run 1:
Wait starts:Sat Jul 01 13:35:33 IST 2017
Unable to locate element.
Wait ends:Sat Jul 01 13:35:43 IST 2017

WAIT TIME: 10 secods

Output of run 2:

Wait starts:Sat Jul 01 14:02:23 IST 2017
Unable to locate element.
Wait ends:Sat Jul 01 14:02:43 IST 2017

WAIT TIME: 20 seconds

You run the same program multiple times. Maximum time you will get wait time as 10 seconds but sometimes 20 seconds.  You will see wait time as 20 seconds rarely.

 When implicit wait time is greater than explicit wait time:

I will just make implicit wait time greater than explicit wait. Run this program multiple times and observe output:


In above case, you will always see time out equal to implicit wait.

When explicit wait time is greater than implicit wait time:

In this case just make explicit wait time greater than implicit wait and run program multiple times.


You will timeout equal to implicit wait time.

So with above example you will find different behavior. You can also notice how implicit wait can ruin your explicit wait functionality. Implicit wait destroys meaning of using explicit wait when using together. So it is advised not to use implicit wait and explicit wait together.

Now we will see reason behind these:

Actually when we use both waits together, both waits will be applied at the same time and it get messed up. We can see it scenarios by scenarios:

  1. Explicit Wait= Implicit Wait => Say 10 seconds.

Both waits get activated at same time to locate element. Explicit wait keeps searching for an element till it is found and implicit wait allows webdriver to search till timeout. When explicit wait starts and looks for element, because of implicit wait it needs to wait for 10 seconds because element is not found. So both waits completes 10 seconds wait time.

But sometime you get wait time as 20 seconds because of synchronization issue. Implicit wait throws exception if element is not found. So till the time implicit wait throws exception,  explicit waits starts another iteration which makes again to wait for 10 seconds. So in this case you will get timeout as 20 seconds.

2. Implicit wait(30) > Explicit Wait(10)

When explicit wait stars looking for element, it needs to wait for 30 seconds because of implicit wait time.

3. Implicit wait(10) < Explicit Wait(30)

When explicit wait starts looking for element, it needs to wait for 10 seconds because of implicit wait. After that implicit wait throws exception because of not able to locate element.  Exception stops explicit wait to search further and doe snot allow to reach its timeout.

That’s it guys. This post took 9 hours for me. I did a lot of experiments before concluding any point. If you find any mistakes or have any doubt feel free to comment.

If you like my posts, please like, comment, share and subscribe. Do not forget to check Frequently Asked JAVA Programs.


Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

51 thoughts on “Are You Mixing Waits In Selenium WebDriver? – A Bad Practise

  1. Hi Amod,

    In the above codes , we have implicit wait then we have explicit wait. when we debug codes in selenium we see that the code works sequentially. ie it will first execute implicit wait and then explicit wait. so here, how are we mixing implicit andexplicit wait

    1. Hi,
      We set implicit wait to apply max wait till the element is located. We write that line above so that it should be applicable for findElement/s. It doesn’t mean that wait statement executed before will have no impact.

  2. Hi Amod/All,

    In second/third scenario u have given a wrong conclusion

    Considering following case no. 2 :

    If u have Implicit wait 10 sec

    And Explicit wait 5 sec
    And search criteria find element by locator only

    //Don’t use any try catch and see what console says in exception

    console will directly say it has waited 5 seconds only for that Element

    You have given 10 seconds of timeout but it has waited only 5 seconds and rest 5 seconds it has waited because both the waits are triggered Same time but not for that Element.

    In third scenario u have taken search criteria as driver.findelement so in same case by default ur webelemnt follows implicit wait

    Conclusion : in second case it has waited 5 seconds only and not 10 seconds.

    In third case if u will take search criteria as driver.findelement it will by default take implicit wait timing even though explicit wait is greater than implicit.

    This is as per my observations and analysis please correct me if someone has other observations/analysis/results

    Thanks :

    1. Hi Omkar,
      Final conclusion is that it will be messed up when you mix both waits. Your above conclusions may reverse when you run the same tests multiple times. So it is really difficult to say what will be exact timeout.

  3. In my selenium hybrid framework i have a testbaseclass which has an implicit wait defined. now all other classes extends this testbase class. if i need to give an explicit wait for one class say class B and given that mixing waits is not good idea… is there a way to comment implicit wait fr class B?

      1. You should create a method for setting explicit wait in ur framrwork. Call and set wait value as required in ur test scripts.

  4. Hi,

    I tried the same thing for IW > EW and IW< EW , My results are exactly opposite to your results .

    PFB code :


    WebDriverWait wait = new WebDriverWait(driver, 30);
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    Stopwatch stopwatch = Stopwatch.createStarted();
    catch(Exception e)
    {System.out.println("Selenium wait for this run was ########################## : " +stopwatch.elapsed(TimeUnit.SECONDS));



    catch (Exception e)
    System.out.println("Selenium wait for this run was ########################## : " +stopwatch.elapsed(TimeUnit.SECONDS));

    catch(Exception e)
    {System.out.println("Selenium wait for this run was ########################## : " +stopwatch.elapsed(TimeUnit.SECONDS));

    RESULTS are :

    Selenium wait for this run was ########################## : 15
    Selenium wait for this run was ########################## : 30
    Selenium wait for this run was ########################## : 15

  5. Hi Amod,

    Thanks for the explanation. I had faced the same question in interview, fortunately I was correct.

    But, I have a doubt, if it is not a good idea to use Implicit wait then everyone should have used explicit wait only, when they to go for Implicit wait? In what case we need to use it?

    Thanks in advance!

    Thank you,

    1. Hello,
      It comes with experience. Every wait has its advantages. Explicit and fluent waits are more efficient. People use as per their convenient. Implicit you need to define once but explicit wait is exclusive for an action. You need to always extra codes for explicit wait.

  6. Hello Amod,

    I have also dove same thing and findings are same .in every case implicit wait will ruin the explicit wait . Then what is the solution or can we will use both in single code?

    Thanks In Advance

      1. Hello Amod,

        I found 1 more thing there are 2 ways to set condition in explicit wait



        if i use 1st line code to set condition then Explicit wait will work correctly bcs in 1st wait m not using driver.findelement , So implicit wait will not work .

        But if i will go with second line of code then only implicit wait will ruin explicit wait.

  7. It would be better if you elaborate the conclusion. Specially 2nd point where implicit wait greater than explicit wait, how it results into exception..?

    1. Because I amhave given wrong loctor so that it should throw an exception. And conclusion I have given clearly. Where you have doubt??

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

Are You Mixing Waits In Selenium WebDriver? – A Bad Practise

by Amod Mahajan time to read: 7 min
%d bloggers like this: