Make Selenium Easy

Part 5: Waits In Selenium: What Happens When We Mix Sleep With Other Types Of Waits ?

Hello Folks,

In this post we will learn about behavior of webdriver when we mix waits together.

There are four types of waits in Selenium Webdriver. Those are:

  1. Thread.sleep()
  2. Implicit wait
  3. Explicit wait (It is also called as webdriver wait.)
  4. Fluent wait. (It is also called as webdriver wait.

Every wait has its own significance and we can use it in different scenarios. But what will happen or we can say in better way, “How webdriver will behave when we use different types of waits together?”.

Let’s think about it.

Mixing Thread.sleep() with any other waits:

  • Thread.sleep() just holds the execution for specified time wherever you use this.
  • If we use any other waits with sleep method, webdriver will just hold the execution for specified time and then will follow other wait.
  • Sleep will not override any waits and vice-versa. For example, if we use sleep of 5 seconds and implicit wait as 30 seconds, in all scenarios webdriver will wait for minimum 5 seconds. Implicit wait will be applicable after that. We can say indirectly you have set time out as 5+30=35 seconds which is maximum and 5 seconds are minimum.
  • Mixing sleep with any other waits will just increase your test execution time. We will understand this with below example:


  1. Open any browser.
  2. Load URL: :”
  3. Type “Ban” in From text box and wait till you get all results.
  4. Select Bangalore.

We define implicit wait and sleep together and assume all elements are available in DOM.



Wait starts:Fri Jun 23 22:41:25 IST 2017
Selected Bangalore
Wait ends:Fri Jun 23 22:41:31 IST 2017
browser closed

Now run the same program by removing sleep:

Wait starts:Fri Jun 23 22:43:10 IST 2017
Selected Bangalore
Wait ends:Fri Jun 23 22:43:11 IST 2017
browser close

Observe both the output. Using sleep and implicit wait together increased your test execution time. It is not good. We should avoid mixing sleep with other waits.

I use term “avoid” because you will find many scenarios where you need to use sleep with other waits. Sometimes predefined timeout is not enough to handle scenarios. Suppose you have defined implicit wait as 30 seconds which is applicable for entire life time of webdriver.  You come up with scenario where you need to increase wait time. You can change implicit timeout but it will impact whole session of webdriver. So easy way is to use Thread.sleep() for extra wait time.

The main learning from above post is that webdriver behaves normally when we use sleep and other waits together. It will not get confused which wait to use. If will follow sleep and other wait in order.

In next post we will see what happens when we mix implicit and explicit wait.

If you have nay doubt, feel free to comment or contact me.

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

7 thoughts on “Part 5: Waits In Selenium: What Happens When We Mix Sleep With Other Types Of Waits ?

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.

Part 5: Waits In Selenium: What Happens When We Mix Sleep With Other Types Of Waits ?

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