无法滚动到视图中" /> org.openqa.selenium.ElementNotInteractableException:尝试单击按钮时,元素 <a class="bg-inverse "> 无法滚动到视图中

org.openqa.selenium.ElementNotInteractableException:尝试单击按钮时,元素 无法滚动到视图中

2023-12-15

我正在使用 gecko 驱动程序 selenium java 和 FF 60.0。以前我的代码工作正常,但突然之间,现在每次运行它时,都会出现错误,如下所示could not be scrolled into view当我尝试单击按钮时。 下面是我的代码,我尝试过Thread.sleep(5000)或隐式等待,但没有任何效果。我被困在这里。

public void goToWorkerSummary() throws InterruptedException {
    WebElement btnWorkerSummary = driver.findElement(By.xpath("//a[@href='/admin/worker-summary']"));
    //Thread.sleep(5000);//wait.until(ExpectedConditions.visibilityOf(btnWorkerSummary).click();
    btnWorkerSummary.click();
}

到目前为止的代码是有效的,但是一旦到达这里,它就会显示上述错误。 下面是错误片段。

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <a class="bg-inverse text-white dropdown-item" href="/admin/worker-summary"> could not be scrolled into view
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:03.216Z'
System info: host: 'CPU-38', ip: '192.168.0.55', os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 60.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 2480, moz:profile: C:\Users\xyz\AppData\Lo..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 6.2, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 08c08933-06f6-480c-88c9-9d7ab718c2c8
    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:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:276)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)

这个错误信息...

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <a class="bg-inverse text-white dropdown-item" href="/admin/worker-summary"> could not be scrolled into view

...意味着Gecko驱动程序 / Firefox驱动程序无法与所需的元素进行交互。

Solution

找到该元素后btnWorker摘要当您调用时继续前进click()代替预期条件 as visibilityOf你需要使用elementToBeClickable()如下:

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='/admin/worker-summary']"))).click();

然而,另一个问题是不兼容您正在使用的二进制版本之间的关系如下:

  • Your 硒客户端版本是3.12.0.
  • Your JDK版本是1.8.0_51这是ancient.

Solution

  • Upgrade JDK到最近的水平JDK 8u201.
  • 执行你的@Test.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

org.openqa.selenium.ElementNotInteractableException:尝试单击按钮时,元素 无法滚动到视图中 的相关文章

随机推荐