4

Does implicit wait set to 30secs will always wait 30secs even if it finds the element at 5 secs? Explicit wait for 30 secs will stop if it met the condition at 5 secs, but does implicit wait do the same?

I also wonder in what cases do we have to use thread.sleep? Sometimes we just need to force some wait time that is not dependent on any condition after performing some action before we proceed to find another element or do another action, do we use thread.sleep or still use webdriverwait?

Thanks.

  • 1
    Yes it does. Check this post for details. – Alexey R. Aug 20 '18 at 16:33
  • 1
    Thanks. Good article. Do you know what cases do we have to use thread.sleep? Sometimes we just need to force some wait time that is not dependent on any condition after performing some action before we proceed to find another element or do another action, do we use thread.sleep or still use webdriverwait? – seleniumappiumnewbie Aug 20 '18 at 16:36
3

Here is the post that gives clear explanation on how exactly implicit wait work in Selenium.

Regarding the cases you should use Thread.sleep in your code I would say that if you wait for the condition that are relevant to UI (i.e. the conditions might be caught by watching UI state like element availability) it is enough to use WebDriverWait. Anyway WebDriverWait eventually calls Thread.sleep but it has a lot of utility code that help to effectively catch UI change moment.

If the delay is required to wait for the state of something different that UI state (for example to wait while the asynchronous transaction to be persisted in database or file) that this is might be a case for Thread.sleep. However Thread.sleep require some supplying code to catch exception, etc.

I would not recommend to overuse Thread.sleep since when you decide to make the code effective for parallel execution there would be a lot of refactoring required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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