This
article is intended to throw light on the two types of waits supported by
Selenium WebDriver – Explicit Wait and Implicit Wait.
What is Explicit Wait
An explicit
wait is the code that we write to wait for a certain condition to occur before
moving on further in the code. There are some convenience methods available
that will help us to write code that will wait only as long as required. WebDriverWait
class in association with ExpectedConditions class is one way to achieve it.
Code sample
that shows the usage of the above mentioned classes is:
What is Implicit Wait
An
ImplicitWait is to tell WebDriver to wait for a certain amount of time when
looking for an element and the element is not immediately available.
Code sample
that shows the usage of ImplicitWait is:
The default setting in implicitlyWait() is 0.
What is best for me?
Using
ExplicitWait is the preferred choice because:
1. In case of Explicit Wait, the WebDriverWait
class will call/ping the ExpectedConditions class every 500 miliseconds whereas
in the case of Implicit Wait, the ping time is 1000 miliseconds so the margin
of error is less by 500 miliseconds.
2. Secondly, once set, implicit wait
remains set for the lifetime of the webdriver object instance which is not the
case with Explicit Wait.
No comments:
Post a Comment