What is the difference between Thread.sleep(6000); and driver.manage().timeouts().implicitlyWait(6,TimeUnit.SECONDS);?

Both the ways are of having waiting time as 6 seconds but Thread.sleep() is only waiting 6 seconds while implict wait is not. what is the reason behind it?

Add Comment
1 Answer(s)

Hi Vijay,

This is a very nice and important question. WebDriver waits are smart in nature as compared to Thread.Sleep.

Let me point out the differences in bullets
– Thread.Sleep waits stops the thread execution for the specified amount of seconds, 6 seconds in your case. During this time there is no other execution that happens in that thread.
– If your element is visible with in the the time limit specified in Thread.Sleep you can do anything, your thread will wait for the specified time before moving to the next statement in the code.
– However, in case of your implicitWait your code will not always wait for the time limit specified. It will wait till the time your element is visible or till the time you have specified. Basically till either of the two condition occurs first.

Next quest is how does implicit wait achieves that?
Implicit wait consists of following steps
1. Look in the DOM for a particular element. If found move out of the wait.
2. If not found wait for 250 milli seconds.
3. After 250 milli seconds poll the DOM again and check for the element. If element found move out of the wait.
4. If element not found, go back to step number 2 and repeat the following steps.

Essentially in implict wait you end up saving time.

A diagram of the sequence will look something like this
RE: What is the difference between Thread.sleep(6000); and 	driver.manage().timeouts().implicitlyWait(6,TimeUnit.SECONDS);?

I hope that clears your doubt.

Virender

Virender Singh Professor Answered on May 1, 2015.

Virender sir, I have one important question which only you can answer I think

If we mention this type of implicit wait in our script once and this will be applied to all code statement of the script

But if we add explicit wait in addition to this wait for specific element who is not working with this wait, then does explicit wait actually overrides the implicit wait or not ?

on May 4, 2015.

Explicit will never override the Implicit wait.It will wait for a specific condition only.check the below links
http://www.toolsqa.com/selenium-webdriver/implicit-explicit-n-fluent-wait/

http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

on May 8, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.