I am trying to use WebDriver's fluentAPI, and am slightly confused with the choices available. I want to wait for an element to become visible. I undertsand that there are many ways available to do this, but I want to specifically understand the difference between the below two methods :
(1)new FluentWait<WebElement>(webElement).
withTimeout(timeoutSeconds, TimeUnit.SECONDS).
pollingEvery(pollingTime, TimeUnit.MILLISECONDS).
untilwait.until(ExpectedConditions.visibilityOf(element));
(2) public void waitForWebElementFluently(WebElement webElement) {
new FluentWait<WebElement>(webElement).
withTimeout(timeoutSeconds, TimeUnit.SECONDS).
pollingEvery(pollingTime, TimeUnit.MILLISECONDS).
until(new Predicate<WebElement>() {
@Override
public boolean apply(WebElement element) {
return element.isDisplayed();
}
}
);
}
What is the difference between using isDisplayed, and visibilityOf?
isDisplayed
:
Is this element displayed or not? This method avoids the problem of having to parse an element's "style" attribute. Source
visibilityOf
An expectation for checking that an element, known to be present on the DOM of a page, is visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0. Source.
So Visibility covers the condition of the element being displayed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With