【问题标题】:Selenium java error com/google/common/collect/ImmutableMap in ubuntuSelenium java 错误 com/google/common/collect/ImmutableMap 在 ubuntu
【发布时间】:2018-09-01 08:11:42
【问题描述】:

嘿,我正在我的 64 位 ubuntu 16.04 系统中用 java 编写一个基本的 selenium 程序。

package test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class App {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "/home/bopsi/webdriver/chromedriver/2.40/chromedriver");
        WebDriver driver = new ChromeDriver();

        String baseUrl = "http://demo.guru99.com/test/newtours/";
        String expectedTitle = "Welcome: Mercury Tours";
        String actualTitle = "";

        driver.get(baseUrl);

        actualTitle = driver.getTitle();

        if (actualTitle.contentEquals(expectedTitle)) {
            System.out.println("Test Passed!");
        } else {
            System.out.println("Test Failed");
        }

        driver.close();
    }
}

这是 maven 项目,这里是依赖项 -

<dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.13.0</version>
        </dependency>
</dependencies>

它给了我以下错误 -

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
    at org.openqa.selenium.remote.service.DriverService$Builder.<init>(DriverService.java:250)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.<init>(ChromeDriverService.java:98)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:91)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at org.qlikhain.auto_liker.App.main(App.java:11)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 5 more

我仔细检查了驱动程序路径并确保它存在于文件夹中。 完全相同的代码在我的 Windows 10 系统中工作。在这两个系统中,我都使用 chrome v68、chromedriver 2.40 和 jdk 1.8。知道为什么它不能在 ubuntu 中工作吗?我是否遗漏了任何重要步骤?

【问题讨论】:

    标签: java selenium


    【解决方案1】:

    文件com/google/common/collect/ImmutableMap很可能已损坏。

    我已经提供了解决这个问题的方法:

    java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap while using WebDriver with Maven Dependencies in Java Selenium

    【讨论】:

      猜你喜欢
      • 2020-04-06
      • 2022-10-07
      • 2018-10-14
      • 1970-01-01
      • 2020-09-16
      • 2019-12-04
      • 1970-01-01
      • 2020-09-12
      • 2018-02-12
      相关资源
      最近更新 更多