硒java 4.1.3
我遵循本教程 https://wwww.javatpoint.com/selenium-webdriver-installation 但是我对WebDriver类有问题:
Error: Unable to initialize main class First
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
我将依赖项如教程所示。如果我相信Selnium API的文档,则WebDriver类在4.1.3版本中。
我不知道是否是因为4.1.3版本没有client client-combiden-3.13.0.jar
file或类似的东西...因此,如果您有解决方案,我'M in。
我在Windows 10上,我使用Eclipse IDE版本2021-06(4.20.0)。
这是我的班级:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class First {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", "/root/drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Launch website
driver.navigate().to("http://www.google.com/");
// Click on the search text box and send value
driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");
// Click on the search button
driver.findElement(By.name("btnK")).click();
}
}
谢谢您的帮助!
I followed this tutorial https://www.javatpoint.com/selenium-webdriver-installation but I have a problem with the WebDriver class :
Error: Unable to initialize main class First
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
I've put the dependencies as shown in the tutorial. And if I trust the documentation of Selnium API, the WebDriver class is present in the 4.1.3 version.
I don't know if it's because the 4.1.3 version don't have the client-combiden-3.13.0.jar
file or something like that... So if you have a solution, I'm in.
I'm on Windows 10, and I use Eclipse IDE version 2021-06 (4.20.0).
And this is my class First :
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class First {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", "/root/drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Launch website
driver.navigate().to("http://www.google.com/");
// Click on the search text box and send value
driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");
// Click on the search button
driver.findElement(By.name("btnK")).click();
}
}
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能只添加以下罐子:
chromedriver
从Chromiumiumiumdriver
继承/code>再次从remotewebdriver
继承,谁最终实现了webdriver
。由于您没有提供这些链接,因此编译器不知道Chromedriver
实施WebDriver
。您至少需要添加以下外部罐子:
注意:您可能也需要添加xxx-sources.jar。这不是必需的,但是您可以将其连接到编译类以查看实际代码,而不是“类文件编辑器”中提供的怪异表示。
您还可以从下载的ZIP中添加所有JAR文件,以防止将来类似的错误。或我首选的方式:查看maven( https:// /Eclipsemaven/article.html )。它可以为您管理依赖项,非常易于使用,您可以更轻松地更新库。您似乎是一个新的程序员,我知道了解所有这些工具看起来很吓人,但是Maven会使您的生活变得更加轻松。
You probably only added the following JARS:
ChromeDriver
inherits fromChromiumDriver
which again inherits fromRemoteWebDriver
who finally implementsWebDriver
. Since you did not provide these links, the compiler cant know thatChromeDriver
implementsWebDriver
.You at least need to add these external JARS:
Note: you might want to add the xxx-sources.jar too. It is not necessary but you can attach it to the compiled classes to see actual code instead of the weird representation eclipse provides in the "Class File Editor".
You can also add all jar files from the downloaded ZIP to prevent similar errors in the future. Or my preferred way: Look into Maven (https://www.vogella.com/tutorials/EclipseMaven/article.html). It manages dependencies for you, is pretty easy to use and you can update your libraries much easier. You seem to be a new programmer and I know it can look intimidating to get to know all these tools, but Maven will make your life quite a bit easier.
因此,对于那些将遇到相同问题的人:
我在 classPath中添加了Java Selenium Zip文件中的所有外部罐子 不在 Modulepath 中。
java的图片构建依赖性
之后,我得到了错误:
slf4j 无法加载类。
: > slf4j-simple-1.7.36.jar 。 simple-1.7.36.jar“ rel =” nofollow noreferrer“> https://repo1.maven.org/maven2/maven2/org/slf4j/slf4j/slf4j-simple/1.7.36/slf4j-slf4j-mimple-1.7.7.7.7.7.7.7.7.7.7.7.jarple
最后,我的最后一个问题是我正在使用的驱动程序,与浏览器版本相比,它不是正确的版本。
So for those who will have the same issues:
I added all external JARs from the Java Selenium zip file in classpath not in modulepath.
Picture of Java Build Path to add dependencies
After that, I got as error :
SLF4J:Failed to load class "org.slf4j.impl.StaticLoggerBinder
.To solve this error, I checked if I had slf4j-api-1.7.36.jar file and I added slf4j-simple-1.7.36.jar. I downloaded it from https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.36/slf4j-simple-1.7.36.jar
And finally, my last issue was the driver I was using, it was not the right version compared to the browser version.
我也遇到了这个错误
java.lang.noclassdeffounderror:org/openqa/selenium/web driver,
然后在classpath中添加了Java Selenium Zip文件中的所有外部罐子。最初,我已经添加到ModulePath。因此,我遇到的错误。
I am also getting this error
java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
Then I added all external JARs from the Java Selenium zip file in classpath. Initially I have added to ModulePath.SO that way I got above error.