Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between element.isDisplayed() and wait.until(ExpectedConditions.visibilityOf(element));

Tags:

selenium

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?

like image 560
user3325862 Avatar asked Jan 11 '23 01:01

user3325862


1 Answers

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.

like image 105
Amey Avatar answered May 26 '23 19:05

Amey