Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

java - What is the exact difference between "ExpectedConditions.visibilityOfElementLocated" and "ExpectedConditions.presenceOfElementLocated"

My apologies in advance if my question sounds primary, I am very new at QA and Selenium.

What is the exact difference between:

 wait.until(ExpectedConditions.visibilityOfElementLocated
                    (By.xpath("//a[text()='Show advanced settings...']"))).click();

and

 wait.until(ExpectedConditions.presenceOfElementLocated
                    (By.xpath("//a[text()='Show advanced settings...']"))).click();

I had a look at here but did not figure it out.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The visibilityOfElmementLocated checks to see if the element is present and also visible. To check visibility it makes sure the element has a height and width greater than 0.

The presenceOfElementLocated just checks the dom to see if it can locate an element no matter its visibility.

Source: https://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#visibilityOf-org.openqa.selenium.WebElement-

visibilityOf public static ExpectedCondition visibilityOf(WebElement element) 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. Parameters:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...