java “ExpectedConditions.visibilityOfElementLocated”和“ExpectedConditions.presenceOfElementLocated”之间的确切区别是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33242882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the exact difference between "ExpectedConditions.visibilityOfElementLocated" and "ExpectedConditions.presenceOfElementLocated"
提问by LoveLovelyJava
My apologies in advance if my question sounds primary, I am very new at QA and Selenium.
如果我的问题听起来很初级,我提前道歉,我是 QA 和 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 herebut did not figure it out.
我看过here,但没有弄清楚。
回答by Joseph Cox
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.
visibilityOfElmementLocated 检查元素是否存在并且是否可见。为了检查可见性,它确保元素的高度和宽度大于 0。
The presenceOfElementLocated just checks the dom to see if it can locate an element no matter its visibility.
PresenceOfElementLocated 只是检查 dom,看看它是否可以定位一个元素,而不管它的可见性。
来源: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:
visibilityOf public static ExpectedCondition visibilityOf(WebElement element) 用于检查已知存在于页面 DOM 上的元素是否可见的期望。可见性是指元素不仅显示出来,而且高度和宽度都大于0。 参数: