ElementNotInteractableException 是 W3C 异常,它被抛出以指示尽管元素存在于 HTML DOM 中,但它不处于可以与之交互的状态。
原因及解决方案:
发生 ElementNotInteractableException 的原因可能有很多。
临时覆盖其他 WebElement 我们感兴趣的 WebElement :
In this case, the direct solution would have been to induce ExplicitWait ie WebDriverWait in combination with ExpectedCondition as invisibilityOfElementLocated as folllows:
WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("xpath_of_element_to_be_invisible")));
driver.findElement(By.xpath("xpath_element_to_be_clicked")).click();
A better solution will be to get a bit more granular and instead of using **`ExpectedCondition`** as **`invisibilityOfElementLocated`** we can use **`ExpectedCondition`** as **`elementToBeClickable`** as follows :
ElementNotInteractableException
ElementNotInteractableException 是 W3C 异常,它被抛出以指示尽管元素存在于 HTML DOM 中,但它不处于可以与之交互的状态。
原因及解决方案:
发生 ElementNotInteractableException 的原因可能有很多。
临时覆盖其他
WebElement
我们感兴趣的WebElement
:In this case, the direct solution would have been to induce
ExplicitWait
ieWebDriverWait
in combination withExpectedCondition
asinvisibilityOfElementLocated
as folllows:WebElement
永久覆盖我们感兴趣的WebElement
:如果在这种情况下覆盖是永久性的,我们必须将
WebDriver
实例转换为JavascriptExecutor
并按如下方式执行点击操作: