我正在使用流畅的等待,因此我可以在一段时间内忽略某些异常,尤其是ElementClickinterceptedException
这就是我宣布等待的方式:
private Wait<WebDriver> initiateWebDriverWait(int timeoutSeconds) {
List allExceptions = new ArrayList();
allExceptions.add(NoSuchElementException.class);
allExceptions.add(ElementNotVisibleException.class);
allExceptions.add(StaleElementReferenceException.class);
allExceptions.add(ElementClickinterceptedException.class);
return new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(timeoutSeconds))
.pollingEvery(Duration.ofMillis(100))
.ignoreAll(allExceptions);
}
用法:
public void waitForElementThenClick(WebElement webElement,int timeOutSeconds) {
waitForElementToBeclickable(webElement,timeOutSeconds);
webElement.click();
}
public void waitForElementToBeclickable(WebElement webElement,int timeoutSeconds) {
Wait<WebDriver> wait = initiateWebDriverWait(timeoutSeconds);
wait.until(ExpectedConditions.elementToBeclickable(webElement));
}
所以当我使用waitForElementThenClick时,我仍然得到
org.openqa.selenium.ElementClickinterceptedException:元素单击被拦截:元素...在点(1338,202)不可单击。其他元素将获得点击:
这是一个随机覆盖,仅在最短的时间内出现,我可以添加100ms等待等等,但是我的主要问题是为什么我什至看到这个异常,当我专门说它忽略它时至少持续5秒钟?而且它并没有等待这5秒钟,所以这不是超时。
有什么想法吗? 是webElement.click();抛出异常?如果是这样,为什么waitForElementToBeclickable返回true?
谢谢