最佳答案
ElementNotInteractableException
ElementNotInteractableException 是 W3C 异常,它被抛出以指示尽管元素存在于 HTML DOM 上, 不处于可以交互的状态。
原因及解决方案:
ElementNotInteractableException 发生的原因有很多。
其他
WebElement
临时覆盖在我们感兴趣的WebElement
上:在这种情况下,直接的解决方案是引入
ExplicitWait
,即WebDriverWait
与 < strong>ExpectedCondition
为invisibilityOfElementLocated
如下: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();
更好的解决方案是更细化,而不是使用
ExpectedCondition
作为invisibilityOfElementLocated
我们可以将ExpectedCondition
用作elementToBeClickable
,如下所示:WebDriverWait wait1 = new WebDriverWait(driver, 10); WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked"))); element1.click();
在我们感兴趣的
WebElement
上永久覆盖其他WebElement
:如果在这种情况下覆盖是永久性的,我们必须将
WebDriver
实例转换为JavascriptExecutor
并执行点击操作如下:WebElement ele = driver.findElement(By.xpath("element_xpath")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", ele);
关于java - 如何解决 ElementNotInteractableException : Element is not visible in Selenium webdriver?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43868009/