isDisplayed() vs isVisible() in Selenium



硒的isDisplayed()isVisible()方法之间有什么区别?两者都用于识别web元素是否隐藏在网页中。

简单的答案是isVisible是旧Selenium RC的方法,isDisplayed是Selenium 2的方法。

如果你说的是WebDrivers WebElement,它只包含isDisplayed()方法,根据文档:

是否显示此元素?这种方法避免了必须解析元素的"style"属性。

在webdriver之前,我们有SeleniumRC,它现在已经被长期弃用了,DefaultSelenium类有isVisible()方法:

确定指定的元素是否可见。元素可以是通过将CSS"visibility"属性设置为"hidden",或将元素的"display"属性设置为"none"如果是它的祖先。如果元素不存在。

参考

如本文所述,Selenium WebDriver';s isDisplayed()方法工作

WebDriver有自己的W3C规范。关于确定可见性的部分可以从规范中为您提供更多信息

Selenium RC-isVisible()-查找display:none样式标记-如果我们不小心的话,这可能会抛出一个空指针。。。因此,要查看元素是否可见,请首先使用isElementPresent()方法检查该元素是否存在。然后尝试检查元素是否可见!请参阅Selenium RC 中isElementPresent和isVisible之间的差异

根据Seleniumv3.141.59的当前版本及其WebElement Interface的文档,方法isVisible()似乎不再受支持,并且一定已被弃用。

其中isDisplayed()在实践中得到了很好的支持。

boolean isDisplayed()
Is this element displayed or not? This method avoids the problem of having to parse an element's "style" attribute.
Returns:
Whether or not the element is displayed

此函数通常暴露于URI模板为的GET请求

/session/{session id}/element/{element id}/displayed

最新更新