What is the exact difference between “ExpectedConditions.visibilityOfElementLocated” and “ExpectedConditions.presenceOfElementLocated”

微笑、不失礼 提交于 2019-12-18 05:45:06

问题


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.


回答1:


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:



来源:https://stackoverflow.com/questions/33242882/what-is-the-exact-difference-between-expectedconditions-visibilityofelementloca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!