硒java错误ubuntu中的com / google / common / collect / ImmutableMap

时间:2018-09-01 08:11:42

标签: java selenium

嘿,我在我的64位ubuntu 16.04系统中用Java编写了一个基本的硒程序。

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中工作吗?我错过任何重要步骤了吗?

1 个答案:

答案 0 :(得分:0)

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

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

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