在 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
。
示例:对于下面隐藏的 span
,Click()
将抛出 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/