selenium - VisibilityOfElementLocated 与 PresenceOfElementLocated

标签 selenium selenium-webdriver webdriver webdriverwait expected-condition

考虑一下:

val element = ...
String str = element.getAttribute("innerHTML")
所以如果我只想得到这个 valuepresenceOfElementLocated()就够了吗?而不是 visibilityOfElementLocated() ?

最佳答案

您可以同时使用 presenceOfElementLocated visibilityOfElementLocated 获取 value .

但从性能角度来看,我猜 presenceOfElementLocated 会稍微快一点,因为它只是检查 元素存在于页面的 DOM 上 .这并不一定意味着该元素是可见的。而 visibilityOfElementLocated 必须检查 元素存在于页面的 DOM 上并且可见 .可见性意味着元素不仅被显示,而且其高度和宽度都大于 0。

所以根据你的情况使用 presenceOfElementLocated 就足够了。

您可以考虑以下几点,根据您的用例选择合适的方法。

  • 使用 presenceOfElementLocated 当你不在乎 if 元素时
    可见与否,您只需要知道它是否在页面上。
  • 使用 visibilityOfElementLocated 当您需要查找元素时
    也应该是可见的。

  • 希望它会帮助你..:)

    关于selenium - VisibilityOfElementLocated 与 PresenceOfElementLocated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38038920/

    相关文章:

    python - Mac 上 Python 中的 Selenium - Geckodriver 可执行文件需要位于 PATH 中

    selenium - 使用 MSTEST 在多个浏览器上运行 selenium

    java - 通过名称和参数在selenium中查找定位器

    java - 如何通过 Jenkins 定位特定的 Cucumber 功能文件(自动化测试)?

    java - 如何控制Selenium WebDriver中点击后出现的新打开窗口?

    Selenium Node 将注册到网格,但不运行任何测试?

    selenium - 由于 FireBug 不再是 FF 56 的选项,如何检查 Selenium v​​3.6 的元素?

    python - 如何隐藏 Firefox 窗口(Selenium WebDriver)?

    javascript - 等待 JavaScript 中的 Tapestry 效果

    python - Python 2.7 中的 Try 语句不返回值