selenium - Selenium 中的 "clickable"元素是否也意味着它是 "visible and present"?

标签 selenium selenium-webdriver webdriver

在 Selenium 框架中,ExpectedConditions.elementIsClickable 是否暗示该元素也是“可见、启用和存在”。 ExpectedConditions.presenceOfElementLocatedBy 本身似乎只是一个简单的 findElement 调用。

通过查看源代码,这是我迄今为止从方法中了解到的 ExpectedConditions 行为:

1.  findElement() = can throw NoSuchElementException, or WebDriverException
2.  elementToBeClickable() = is visible, !null, and enabled, catches
      a StaleElementReferenceException
3.  visbilityOf()  =   displayed, catches no exception
4.  presenceOfElementLocated()  =   simple findElement call,  catches findElement() 
      exceptions
5.  stalenessOf() =  true if findElement succeeds, can catch StaleElementReferenceException,
      or findElement() exceptions
6.  visibilityOfElementLocated() = same as stalenessOf, can catch 
      StaleElementReferenceException or the findElement() exceptions

最佳答案

是的,可点击元素要求元素可见。如果元素被隐藏,Click() 将失败并抛出 ElementNotVisibleException

示例:对于下面隐藏的 spanClick() 将抛出 ElementNotVisibleException ,并显示消息 Element 目前不可见,并且因此可能无法与之交互

var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("data:text/html,<span id=\"hello\" style=\"display:none;\">Hello</span>");
driver.FindElement(By.Id("hello")).Click();

关于selenium - Selenium 中的 "clickable"元素是否也意味着它是 "visible and present"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22674640/

相关文章:

java - 使用带有 Java 的 Selenium WebDriver 在组中选择单选按钮

javascript - 获取错误 : Promise rejected with no or falsy reason in mocha selenium node js

java - ExpectedConditions.refresh 和 ExpectedConditions.stalenessof 之间有什么区别

java - 如何让 Selenium WebDriver 等待 HTML5 视频(jwplayer)完成?

java - 在 Selenium Webdriver 中使用鼠标移动下拉滚动条

java - 我如何从下拉列表中添加元素然后获取每个元素的文本

c# - Selenium :意外错误。 System.Net.WebException:无法连接到远程服务器

python - 从网站中的警报中获取文本

selenium - 如何使用 Selenium WebDriver 等待重定向链在最终页面加载不可预测的情况下解决?

java - 如何在CF中获取java类