How to resolve ElementNotInteractableException: Element is not visible in Selenium webdriver?(如何解决 ElementNotInteractableException:元素在 Selenium webdriver 中不可见?)
问题描述
这里有我的代码图像和错误图像.谁能帮我解决这个问题?
Here I have the image of my code and the image of my error. Can anyone help me to resolve this issue?
推荐答案
ElementNotInteractableException
ElementNotInteractableException 是 W3C 异常,它被抛出以表明虽然元素存在于 HTML DOM,它不是处于可以交互的状态.
ElementNotInteractableException
ElementNotInteractableException is the W3C exception which is thrown to indicate that although an element is present on the HTML DOM, it is not in a state that can be interacted with.
ElementNotInteractableException 发生的原因有很多.
我们感兴趣的
WebElement
上的其他WebElement
的临时覆盖:
Temporary Overlay of other
WebElement
over theWebElement
of our interest :
在这种情况下,直接的解决方案是引入 ExplicitWait
即 WebDriverWait
与 ExpectedCondition
as invisibilityOfElementLocated
如下:
In this case, the direct solution would have been to induce ExplicitWait
i.e. 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();
更好的解决方案是更细化,而不是使用 ExpectedCondition
作为 invisibilityOfElementLocated
我们可以使用 ExpectedCondition
作为 elementToBeClickable
如下:
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:
WebDriverWait wait1 = new WebDriverWait(driver, 10);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));
element1.click();
将其他 WebElement
永久覆盖在我们感兴趣的 WebElement
上:
Permanent Overlay of other WebElement
over the WebElement
of our interest :
如果在这种情况下叠加层是永久的,我们必须将 WebDriver
实例转换为 JavascriptExecutor
并执行如下点击操作:
If the overlay is a permanent one in this case we have to cast the WebDriver
instance as JavascriptExecutor
and perform the click operation as follows:
WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
这篇关于如何解决 ElementNotInteractableException:元素在 Selenium webdriver 中不可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何解决 ElementNotInteractableException:元素在 Selenium webdriver 中不可见?
基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01