如何检查100%覆盖的WebElement是否可以与Selenium一起点击
我有两个具有绝对位置的div
Visible later To be removed
和一些Javascript(这里没有显示)从DOM中删除4712一段时间(比如说2秒后)。
现在,在我的Selenium测试中,我想检查4711是否可点击。 从用户的角度来看,只有在删除4712后才能点击它。
所以我试过了
new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.elementToBeClickable(By.id("4711")));
但是,4711始终是可点击的(启用=真,显示=真),即使在删除4712之前也是如此。
有没有办法如何检查4711是否真的可以点击,也就是说,从用户的角度可以点击(理想情况下不使用Javascript)?
在检查4711的可点击性之前,您是否尝试等待4712的隐身.4711仍然可以注册为可点击而4712仍然可见并且可能导致问题。
new WebDriverWait(browserInstance.getWebDriver(), 5).until(!ExpectedConditions.elementToBeVisible(By.id("4712"))); new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.elementToBeClickable(By.id("4711")));
正如您所提到的, Javascript删除了元素4712 ,如果元素变得陈旧或变得不可见 ,则有点不清楚。 因此,对于此步骤,您可以使用以下任一选项:
-
stalenessOf()
:new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.stalenessOf(driver.findElement(By.id("4712"))));
-
invisibilityOfElementLocated()
:new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.invisibilityOfElementLocated(By.id("4712")));
-
not
与visibilityOfElementLocated()
new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.not(ExpectedConditions.visibilityOfElementLocated(By.id("4712"))));
-
not
与presenceOfElementLocated()
new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.not(ExpectedConditions.presenceOfElementLocated(By.id("4712"))));
对于下一步,您要validation元素4711是否可点击,您可以使用以下代码行:
new WebDriverWait(browserInstance.getWebDriver(), 5).until(ExpectedConditions.elementToBeClickable(By.id("4711")));
注意 :元素的状态为enabled=true
且displayed=true
不等同于元素是可interactable
clickable