Why not to use Thread.sleep(); to achieve synchronization in selenium?

thread.sleep() in selenium
One of the way to achieve synchronization, implement wait is by calling Thread.sleep() function however, it is not recommended because this is not very stable and unreliable. The time has to be specified in milliseconds.
I think Thread.sleep() is considered as the worst case of explicit wait because, for Thread.sleep(), it has to wait for the full time specified as the argument of Thread.sleep(), before proceeding further.
it is not related to Implicit wait or Explicit wait…So we should not be confused due to resemblance in Sync method in Selenium and Thread.sleep.
The main disadvantage for Thread.sleep;statement is, there is a chance of unnecessary waiting time even though the application is ready.
We can achieve synchronization using Thread.Sleep, method of Java. However this is not recommended methodology. As it is same like asking selenium to stop executing for given X milliseconds so that our control is loaded and it is not guaranteed that within that hard coded X value, control is fully loaded and our test code can execute safely.
Ex: Thread. Sleep (20000);
Here the execution is halted for 20 Sec., even if the object we are looking exists at that instant, so it unnecessary waits of 20 sec.
or
Control exists after 10 sec. So here also selenium unnecessarily waits for more 10 sec.

Refer below posts to understand more about various types of synchronization.

Hope this helps.

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

https://www.youtube.com/automationtalks

Get the Framework code at Github Repo: https://github.com/prakashnarkhede?tab=repositories