英文:
Getting an error when I try to run a simple Java - Selenium project
问题
我尝试运行这个简单的项目。我已经将所有 Selenium JAR 文件应用到了构建路径中,`chromedriver` 文件位于我的桌面上:
```java
package XYZ;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumScript {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "/Users/MYNAME/Desktop/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://google.com/");
System.out.print(driver.getTitle());
driver.quit();
}
}
但我得到了以下错误:
Juli 20, 2023 11:35:03 AM org.openqa.selenium.remote.service.DriverService$Builder getLogOutput
INFORMATION: 默认情况下不再将驱动程序日志发送到控制台;https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/io/ByteStreams
at org.openqa.selenium.remote.service.DriverService$Builder.getLogOutput(DriverService.java:471)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.createDriverService(ChromeDriverService.java:417)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.createDriverService(ChromeDriverService.java:197)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:507)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:166)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:50)
at rocketlaunch.SeleniumScript.main(SeleniumScript.java:11)
Caused by: java.lang.ClassNotFoundException: com.google.common.io.ByteStreams
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 7 more
我期望控制台输出页面标题。
<details>
<summary>英文:</summary>
I try to run this simple project. I have all Selenium JAR files applied in the build path and the `chromedriver` file is located on my desktop:
package XYZ;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumScript {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("websdriver.chrome.driver", "/Users/MYNAME/Desktop/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://google.com/");
System.out.print(driver.getTitle());
driver.quit();
}
}
And I get the following error:
```lang-none
Juli 20, 2023 11:35:03 AM org.openqa.selenium.remote.service.DriverService$Builder getLogOutput
INFORMATION: Driver logs no longer sent to console by default; https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/io/ByteStreams
at org.openqa.selenium.remote.service.DriverService$Builder.getLogOutput(DriverService.java:471)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.createDriverService(ChromeDriverService.java:417)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.createDriverService(ChromeDriverService.java:197)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:507)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:166)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:50)
at rocketlaunch.SeleniumScript.main(SeleniumScript.java:11)
Caused by: java.lang.ClassNotFoundException: com.google.common.io.ByteStreams
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 7 more
I expect the console to output the page title.
答案1
得分: 1
com.google.common.io.ByteStreams
类是 Guava 库的一部分。您需要将此库添加到您的类路径中。
如果您使用 Maven,您可以添加以下依赖项:
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.1-jre</version>
</dependency>
到您的 POM 中。
如果您不使用 Maven,请下载 JAR 文件并手动将其添加到类路径中。
顺便说一句:请注意 Java 命名约定。包名应为小写。
英文:
The class com.google.common.io.ByteStreams
is part of the Guava libraries. You have to add this library to your class path.
If you use Maven, you can add the dependency:
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.1-jre</version>
</dependency>
to your POM.
If you not use Maven, download the JAR file and add it to the class path manually.
BTW: Take care of Java naming conventions. Package names should be lowercase.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论