【问题标题】:What is the exact difference between "ExpectedConditions.visibilityOfElementLocated" and "ExpectedConditions.presenceOfElementLocated"“ExpectedConditions.visibilityOfElementLocated”和“ExpectedConditions.presenceOfElementLocated”之间的确切区别是什么
【发布时间】:2016-01-19 11:31:46
【问题描述】:

如果我的问题听起来很重要,我提前道歉,我是 QA 和 Selenium 的新手。

两者之间的确切区别是什么:

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

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

我查看了here,但没有弄明白。

【问题讨论】:

    标签: java selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    visibilityOfElmementLocated 检查元素是否存在并且是否可见。为了检查可见性,它确保元素的高度和宽度大于 0。

    presenceOfElementLocated 只是检查 dom 以查看它是否可以定位元素,无论其可见性如何。

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

    可见性 公共静态 ExpectedCondition visibilityOf(WebElement 元素) 期望检查已知存在于页面 DOM 上的元素是否可见。 可见性是指元素不仅显示出来,而且高度和宽度都大于0。 参数:

    【讨论】:

    • 所以如果一个元素存在但不可见我们不能点击它但是如果它可见并且存在我们可以做到,对吧?
    • 正确。除非您使用 javascript 点击。
    • javascript点击怎么样?我需要用javascript编写代码吗?!! :(
    • JavascriptExecutor js = (JavascriptExecutor)驱动程序;对象元素 = enterelementhere(驱动程序); js.executeScript("arguments[0].click();", element);
    • 另外,如果您认为我的回答是正确的,请选择它。谢谢。
    猜你喜欢
    • 2021-05-19
    • 2016-01-19
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多