java.lang.NoClassDefFoundError:使用GeckoDriver Firefox通过Java中的Selenium出现com/google/common/collect/ImmutableMap错误 [英] java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap error using GeckoDriver Firefox through Selenium in Java

查看:580
本文介绍了java.lang.NoClassDefFoundError:使用GeckoDriver Firefox通过Java中的Selenium出现com/google/common/collect/ImmutableMap错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码,它给了我这个错误:

I am using this code and it is giving me this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
        at org.openqa.selenium.firefox.FirefoxDriver.<clinit>FirefoxDriver.java:108)
        at Selenium_1.main(Selenium_1.java:13)
    Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 2 more

无法解决.我正在日食中工作,请你帮我一下.

Unable to solve it. I am working in eclipse, could you please help me out.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//comment the above line and uncomment below line to use Chrome
//import org.openqa.selenium.chrome.ChromeDriver;

public class Selenium_1 {
        public static void main(String[] args) {
            // declaration and instantiation of objects/variables
            System.setProperty("webdriver.firefox.marionette","C:\\Program Files\\Java\\jre1.8.0_231\\lib\\ext\\geckodriver.exe");
            //System.setProperty("webdriver.chrome.driver", "/path/to/chrome driver");
            WebDriver driver = new FirefoxDriver();
            //comment the above 2 lines and uncomment below 2 lines to use Chrome
            //System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
            //WebDriver driver = new ChromeDriver();

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

            // launch Fire fox and direct it to the Base URL
            driver.get(baseUrl);

            // get the actual value of the title
            actualTitle = driver.getTitle(); 

            /*
             * compare the actual title of the page with the expected one and print
             * the result as "Passed" or "Failed"
             */
            if (actualTitle.contentEquals(expectedTitle)){
                System.out.println("Test Passed!");
            } else {
                System.out.println("Test Failed");
            }



            //close Fire fox
            driver.close();
        }
    }

如果您需要了解其他任何信息,请告诉我...我完全被困住了...帮助!帮助!帮助!

Please let me know if you need to know anything else... i am totally stuck... HELP! HELP! HELP!

推荐答案

此错误消息...

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
    at org.openqa.selenium.firefox.FirefoxDriver

...表示文件com/google/common/collect/ImmutableMap可能已损坏,或者您正在使用的特定二进制文件的版本与 guava version /依赖(专家).

...implies that the file com/google/common/collect/ImmutableMap might be corrupted or there is some incompatibility between the version of the binaries you are using specifically with the guava version / dependency (maven).

您需要采取以下几项措施:

You need to take of a couple of things as follows:

  • System.setProperty()行中,您需要将webdriver.firefox.marionette更改为 webdriver.gecko.driver .如此有效,代码行将是:

  • In the System.setProperty() line you need to change webdriver.firefox.marionette to webdriver.gecko.driver. So effectively, the line of code will be:

System.setProperty("webdriver.gecko.driver","C:\\Program Files\\Java\\jre1.8.0_231\\lib\\ext\\geckodriver.exe");

  • 如果您使用的是删除corrup/不兼容的.m2文件夹可以解决您的问题.

  • Incase you are using maven deleting the corrup/incompatible .m2 folder can solve your issue.

    JDK 升级到最新级别

    Upgrade JDK to recent levels JDK 8u222.

    您可以在以下位置找到相关讨论:

    You can find a relevant discussion in:

    这篇关于java.lang.NoClassDefFoundError:使用GeckoDriver Firefox通过Java中的Selenium出现com/google/common/collect/ImmutableMap错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆