java - 硒:NoClassDefFoundError WebDriverException
问题描述
在某些(看似随机的)情况下,使用 Selenium 和 Chrome 无头网络驱动程序时出现以下错误:
java.lang.NoClassDefFoundError: Could not initialize class org.openqa.selenium.WebDriverException
我猜某些元素在导致异常的浏览器中不可用,但没有异常消息我无法确定。
我的 pom.xml 中有这个:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-7</version>
</dependency>
我可以在我的代码中创建一个 WebDriverException 的虚拟实例。那么可能是什么问题?
更新:我还看到了其他类型的 Selenium 异常,没有消息。这是堆栈跟踪的另一个示例:
java.lang.NoClassDefFoundError: Could not initialize class org.openqa.selenium.ElementClickInterceptedException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:196)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:129)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:167)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:123)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:501)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:238)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
解决方案
WebDriverException
类是Selenium API发行版的一部分。您的 POM 中缺少该依赖项。除此之外,除非您正在进行评估,否则请远离 alpha 版本。始终使用稳定版本。
推荐阅读
- javascript - 在Javascript中从数组中选择并删除随机单词
- mysql - Visual Studio 2019中EntityFramework向导连接MySql的问题如何解决?
- php - 从外部链接链接时基于会话的 CSRF 令牌
- c# - 如何在 C# 中使用备用凭据映射网络打印机
- javascript - 滚动时将图像从灰度变为彩色
- bash - 如何运行bash嵌套函数
- apache-flink - 集群在 statefun 上运行时是否可以添加新的嵌入式工作人员?
- node.js - 根据情况安排邮件
- postgresql - Spring 事务和 postgres(VACUUM,在事务外部运行)
- linux - 从 Jenkins 中的 Shell 触发作业