简体   繁体   中英

getting Exception in thread “main” java.lang.NoClassDefFoundError: com/google/common/base/Function

ok i am using
eclipse neon Client-combined-3.1.0-nodeps.jar for firefox-setup 39.0

and this is my code

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class T1 {

    public static void main(String[] args){


    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);


    driver.navigate().to("https://www.orbitz.com/");

    driver.manage().window().maximize();

    driver.findElement(By.xpath(".//*[@id='primary-header-hotel']")).click();


    String result = driver.getPageSource();

    System.out.println("result is "+" "+ result);

    driver.close();
}

}

and this is the error

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function at T1.main(T1.java:12) Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more

i have seen a solution to add path for guava-21.0

but more error

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver . The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases at com.google.common.base.Preconditions.checkState(Preconditions.java:738) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:111) at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38) at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:112) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:302) at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:312) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:272) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:267) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:263) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:122) at T1.main(T1.java:12)

after adding line of code and still Client-combined-3.1.0-nodeps.jar firefox 52.0.1 and using geckodriver-v0.15.0-win64 and still getting the same error

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;



public class T1 {

    public static void main(String[] args){

    System.setProperty("webdriver.gecko.driver","C:\\Users\\ahmed\\Desktop\\geckodriver.exe"); 
    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);


    driver.navigate().to("https://www.orbitz.com/");

    driver.manage().window().maximize();

    driver.findElement(By.xpath(".//*[@id='primary-header-hotel']")).click();


    String result = driver.getPageSource();

    System.out.println("result is "+" "+ result);

    driver.close();
}

}

here is the error

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function at T1.main(T1.java:14) Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more

In Selenium 3.1.0 you have to do the following to initialize the gecko driver:

System.setproperty("webdriver.gecko.driver","C:\\\\geckodriver_location\\\\geckodriver.exe");

Webdriver driver = new Firefoxdriver();

Run your code. It should be success. Let me know if this works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM