我有一个简单的Selenium测试代码:
var xhr = new XMLHttpRequest();
var imgTag = new Image();
imgTag.src = 'data:image/webp;base64,UklGRnATAABXRUJQVlA4IGQTAACQdACdASpAAfAAPrVSo02nJCMvJTBcaeAWiUDjNPPwBPRpD0fMm4cxS7x2+Z3q/qF3D3PJaeLK66etXdv0O49SJ4hajH956Jnwz/uG+yaLAS+QQdX8gg9taM/8crC8nQ6ImBsmWjkif3HncRfyIHYkkeBJ53yKMOaOAn7yHi5JN3Qtcjvyicm8n4CDtxO+qP/sUN8L2gmYuvwQbLWHJ2TeDK4wJJsOL9lbF3w31T3uEGtGDoti3saQam1oNgS5NGwovbWeyBLUhRbpRliWhHAg6Fuh0bKvd0HsB6RL+9s+vZy2vTz0VxZN+hHcSe046+jikJ8laxyIUtVAXw91KVAP8tpH3Fikc0IKZwJjE7Xmc6wzOdxwgyeW76UzE0Ow+T0NIc5Rlt9J8OpABGaH6T2n51PhziFEizoC1BRaycjl4Yhkbz/E4ivXPPxu9wdB1XVKRfZSU4tgPkGr+y9i+QMLb5XYvGWl3ahnf/NCENWsbKUYF5gpCTK6nHuXuqlxVZk7LueKG1gWVm6piBGU/xnu6m73TM8w/+p3VF4GApEdzb7kaxVgIhx4Jat1QJVgB+YwNcEwc/9jbHIDYLV+4FZ1aY6EJb+mUUfx1gFjkLo8OfNmAYj6Xj2LZaVc56vvlVymUlqQxaLzRSyBZKuIcQcZoX3zl+m2G6gxrCJI03UrZun8yXGaOLlDR+9asPtZYj5b+bOMSqNPHQOr+Q+/YSNz9LXDMGboC757u5leZIfuyz1Ztj8PFRukI2xeQ7H6hYUKsTzJSHxIlMS2IUNLYq6xF8fQIY3JTPbpqRjcIRHuA1dfMaSlUfYDRS87zTwUsjzm91COqW50UcFjhSzRACFbpvqi7p9nro299QFowz0FYtZ7NGLBh0RgOTh7jIImuUdLJHOcFUmJnR8RRYXdFPQLpwymeAXf3p35c0kvjAkJzq5/+DFa848DK6f1616ymjEsnXgLISDXZYzJUcQ53riPrOb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Kz/R02DpXdyFr8iTFXg2JNi4miqfKdG2bZAOnjuxSY5NWUUWS0CLlHbFGAH+eHZ0u7vCb/QjM2d0rhK+lvhbeofeBMFelif39yAtQa1Su1okKKNdAr809c8EHImzkGR4kP69qdwGkZFS9A1kHS8Ry2/12WaRVrDXADCLUyn0AxvlfWoRVgrXNn7rW8Vkpi0pLnMaLDKQa8HEqhqQmTvCut5i1yT/EH+r96H2qvn8CCJnPPwYWq16+OjunCKOPHEPQdzOUdSiht3AuHwW1b8VHQAAAA==';
xhr.open('get', imgTag.src);
xhr.responseType = 'arraybuffer';
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var webp_data = new Uint8Array(xhr.response);
decode(webp_data);
}
};
xhr.send();
我得到了这个错误:
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/home/chromedriver");
WebDriver driver= new ChromeDriver();
driver.get("http://google.com");
}
我认为jar和Dependency都可以,但我仍然会收到此错误
答案 0 :(得分:1)
错误说明了一切:
Exception in thread "main" java.lang.NoClassDefFoundError: okhttp3/ConnectionPool | Caused by: java.lang.ClassNotFoundException: okhttp3.ConnectionPool
NoClassDefFoundError
NoClassDefFoundError
无法在运行时找到编译时可用的特定类时,会发生Java中的 Java Virtual Machine
。例如,如果我们已经从类中解析了方法调用或访问了类的任何静态成员,并且该类在运行时不可用,那么 JVM
将抛出 { {1}} 强>
错误清楚地表明您错误配置了类路径。除非您告诉我们如何运行测试,您使用哪个构建器或IDE以及构建器配置文件或项目描述,否则很难调试问题的确切原因,除非您告诉我们如何运行测试。
从上述所有观点可以清楚地看出,相关的 NoClassDefFoundError
或 Class
是从一个来源 {{1在 Methods
期间无法使用。
如果通过 Compile Time
/ Run Time
/ {存在多个来源来解析类和方法,则会出现这种情况{1}} 强>
此时值得一提的是 selenium-java-3.9.x 客户端确实依赖 okhttp ,您可以找到dependency list here
还应注意:
根据Can't launch chrome browser using latest selenium 3.9.0启动Chrome时存在一些问题。
要解决来自 Selenium v3.9.1 的问题,OkHttp支持的实例现在可以连接到需要授权的服务器,该服务基于PR #5444。
以下是解决 JDK
错误的几个步骤:
Maven
或 Gradle
,删除所有 NoClassDefFoundError - okhttp3/ConnectionPool
的 Maven
即可。 Gradle
或 External JARs
将下载并解决所有必需的依赖项。Java Build Path
中使用 Maven
,只需在 Gradle
> Selenium JARs
并删除未使用的。Java Project
时,请使用 External JARs
或 Java Build Path
。避免同时使用两者。Maven
。答案 1 :(得分:1)
请检查您项目库中的jar文件:
okhttp-3.10.0.jar
和okio1.14.1.jar
可以使用此jar文件解决您的问题:
java.lang.NoClassDefFoundError:okhttp3 / ConnectionPool
答案 2 :(得分:0)
我希望,你没有上课就尝试了一种方法。请尝试将主要方法放在课堂上。如果您有任何进一步的错误,请告诉我。
班级考试{
public static void main(String [] args){
System.setProperty("webdriver.chrome.driver", "youHaveToUseLocationWhereYouHaveYourChromeDriver");
WebDriver driver= new ChromeDriver();
driver.get("http://google.com");
} }
答案 3 :(得分:0)
我有与此相同的问题。通过遵循上述建议,并将Selenium客户端JAR(包括源代码)添加到modulepath中,并将Selenium服务器JAR添加到classpath中,它可以正常工作。