How to solve java.lang.NoClassDefFoundError? Selenium

前端 未结 1 1343
谎友^
谎友^ 2020-12-22 14:01

Why this code doesn\'t work?

import org.junit.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MainTe         


        
相关标签:
1条回答
  • 2020-12-22 14:41

    The error says it all :

    java.lang.NoClassDefFoundError: com/google/common/base/Function
    at MainTest.openGoogle(MainTest.java:15)
    

    While working with Selenium v3.x you have to download geckodriver.exe from mozilla/geckodriver and place it in your system. Next you have to set the system property through the line System.setProperty() as follows and provide the absolute path of the GeckoDriver binary within your system as follows :

    @Before
    public void openGoogle()
    {
        System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
        wd = new FirefoxDriver();
        urll = "https://google.com";
    }
    

    Finally Instead of mentioning import org.junit.*; as per best practices mention the distinct exports as follows :

    • import org.junit.Before;
    • import org.junit.Test;
    • import org.junit.After;

    Here you can find a detailed discussion on NoClassDefFoundError

    0 讨论(0)
提交回复
热议问题