Thursday, October 20, 2011

WebDriver waitForElement - waits for an element until given number of secs

public void waitForElement(final By by, long timeout) throws Exception {

(new WebDriverWait(DriverFactory.getDriver(), timeout))
.until(new ExpectedCondition() {
public Boolean apply(WebDriver d) {
return isElementPresent(by);
}
});
}

The above code can be used to wait for an element until it is displayed in webpage.
On new page loads we can use this command to wait before performing a new action by waitForElement which is a mandatory element to be displayed on page/section/frame refresh completes.

No comments: