what is WebDriver wait?
when running test suite if need to wait for an element the webDriver has to wait till the element appears, this can be done either by defining static time out in such cases though the element is displayed still webDriver has to wait till the time out occurs.
An implementation of the
Wait interface that may have its timeout and polling interval configured on the fly.But Using WebDriver wait interface, WebDriver will wait for that particular amount of X duration in such a way that it will check for every Y duration(Both X,Y are configurable) whether the element is displayed or not, it is like dynamic wait.
Syntax:
// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 5 seconds.
FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
The below code can be used in a method, if need to wait for an element before proceeding further in testsuite.
wait.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver d)
{ return d.findElement(By.id("XYZ")); }});
I use the above syntax contents in method when need to wait for a element when running my test suite
-----------------------------------------------------------------
Note: For more information please see the link below
Comments