Reputation: 179
I am having some confusion regarding Implicit wait method provided by Selenium Webdriver.
When to Use Implicit wait
a- For Page Load (when Using driver.get) or for Ajax PopUp Load Like let say I am entring something in Edit Box and some Look up or Ajax call is happening.
Where To Use Implicit wait
Should I use after all the methods wherever Ajax call or Page load happening or only once it is enough (I am just taking the reference from Selenium RC where We can Use Selenium.SetSpeed Method).
Thanks, Arun
Upvotes: 4
Views: 6519
Reputation: 3649
For ajax call, I would prefer Explicit wait. But if you can figure out what is the min timestamp of your ajax calls you can provide in implicitlyWait.
Implicitwait is enforced on the driver permanently. So u need not declare again and again. It would affect the driver to wait for a particular time until it throws NoSuchElementException
. But if you are using xpaths more, then it would be better you provide greater timeouts in implicitly wait.
Another thing to add, implictlyWait affects only findElement and findElements functions. Other functions are unaffected of it.
Upvotes: 0
Reputation: 1956
Example:
WebDriverWait explicit_wait_Example = new WebDriverWait(driver, 10);
explicit_wait_Example.until(ExpectedConditions.elementToBeClickable(By_Locator)).click();
Above is the example of using explicit wait with until which is one of the most efficient and effective ways to use such kind of wait.
Upvotes: 0
Reputation: 16201
An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. The worst case of this is Thread.sleep()
, which sets the condition to an exact time period to wait. There are some convenience methods provided that help you write code that will wait only as long as required. WebDriverWait
in combination with ExpectedCondition
is one way this can be accomplished.Example is as follows:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
However, depending on the language implementation varies a little bit. See here more about ExpectedCondition
An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance. Below is an implementation of implicit wait:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Both of these definitions are from seleniumhq and most perfect definition out there.
There is a great explanation in toolsQA how and when to use them. Plus a comparison between implicit, explicit and FLUENT waits which are worth taking a look.
Upvotes: 6