java - org.openqa.selenium.ElementNotInteractableException : Cannot click on element

标签 java selenium selenium-webdriver automation

我试图单击 Web 应用程序中的下拉菜单,然后单击 DIV 中的子项目。下面是我试图执行的代码。

WebElement mnuElement;
WebElement submnuElement;

mnuElement = driver.findElement(By.id("CollectorsTab"));
//  Thread.sleep(3000);

submnuElement = driver.findElement(By.id("IdentityCollectorsTab"));

Actions builder = new Actions(driver);
// Move cursor to the Main Menu Element
builder.moveToElement(mnuElement).perform();
// Pause 2 Seconds for submenu to be displayed
TimeUnit.SECONDS.sleep(2); //Pause 2 seconds
// Clicking on the Hidden submnuElement
submnuElement.click();

我读过一些关于尝试更多等待的问题,我也尝试过,但我总是遇到以下错误。

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Cannot click on element
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'
System info: host: 'UKPC31732', ip: '172.31.1.202', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{acceptInsecureCerts=false, browserVersion=11, se:ieOptions={nativeEvents=true, browserAttachTimeout=0, ie.ensureCleanSession=false, elementScrollBehavior=0, enablePersistentHover=true, ie.browserCommandLineSwitches=, ie.forceCreateProcessApi=false, requireWindowFocus=false, initialBrowserUrl=http://localhost:1486/, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, ignoreProtectedModeSettings=false}, browserName=internet explorer, pageLoadStrategy=normal, javascriptEnabled=true, platformName=WINDOWS, setWindowRect=true, platform=WINDOWS}]
Session ID: e6579c86-fd88-4ce0-8820-1d4c644ba7ee
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
    at FlowIAM.main(FlowIAM.java:67)

最佳答案

尝试下面的代码来单击子菜单

WebElement mnuElement;
WebElement submnuElement;

mnuElement = driver.findElement(By.id("CollectorsTab"));
submnuElement = driver.findElement(By.id("IdentityCollectorsTab"));

Actions action = new Actions(driver);
action.moveToElement(mnuElement).clickAndHold(submnuElement).click().build().perform();

有时我们需要单击并按住,然后必须单击子菜单。希望这段代码有帮助

关于java - org.openqa.selenium.ElementNotInteractableException : Cannot click on element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46861561/

相关文章:

java - 无需浏览器即可在服务器上打印html文件

java - 数据核空间映射误差

java - 获取 "Exception in thread "main“java.lang.NoSuchMethodError : org. openqa.selenium.WebElement.setSelected()V”错误

regex - 我们可以在 xpath 值中使用正则表达式吗?

selenium - 无法通过 TestNG Dataprovider 并行运行超过 10 个测试

java - 出现不可预测的弹出窗口 - 如何使用 Selenium (Java) 处理此问题?

java - 如何单击位于另一个跨度内的跨度内的按钮?

java - 为什么我们可以将数组分配给 Java 中 Object 类型的引用?

java - 是否可以使用 Java 截断和启用 HBase 表?

java - 驱动服务器意外死机了!含 Selenium