簡體   English   中英

在線程“ main”中獲取異常java.lang.NoClassDefFoundError:com / google / common / base / Function

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

好的,我正在使用
用於Firefox 39.0的eclipse neon Client-combined-3.1.0-nodeps.jar

這是我的代碼

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();
}

}

這是錯誤

線程“主”中的異常java.lang.NoClassDefFoundError:com / google / common / base / Function at T1.main(T1.java:12)由以下原因引起:java.lang.ClassNotFoundException:com.google.common.base.Function在java.net.URLClassLoader.findClass(未知源)在java.lang.ClassLoader.loadClass(未知源)在sun.misc.Launcher $ AppClassLoader.loadClass(未知源)在java.lang.ClassLoader.loadClass(未知源) ...還有1個

我已經看到了為番石榴21.0添加路徑的解決方案

但是更多的錯誤

線程“主”中的異常java.lang.IllegalStateException:驅動程序可執行文件的路徑必須由webdriver.gecko.driver系統屬性來設置;否則,必須執行以下操作: 有關更多信息,請參見https://github.com/mozilla/geckodriver 可以從org.openqa.selenium.remote.service上的com.google.common.base.Preconditions.checkState(Preconditions.java:738)上的https://github.com/mozilla/geckodriver/releases下載最新版本。 org.openqa.selenium.firefox.GeckoDriverService $ Builder.findDefaultExecutable(java.org ),位於org.openqa.selenium的org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:312)的org.openqa.selenium.remote.service.DriverService $ Builder.build(DriverService.java:302)上。 org.openqa.selenium上的firefox.FirefoxDriver。(FirefoxDriver.java:272).org org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:263)上的firefox.FirefoxDriver。(FirefoxDriver.java:267)。 openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:122)位於T1.main(T1.java:12)

添加代碼行后,仍然將Client-combined-3.1.0-nodeps.jar firefox 52.0.1並使用geckodriver-v0.15.0-win64仍然出現相同的錯誤

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();
}

}

這是錯誤

線程“主”中的異常java.lang.NoClassDefFoundError:com / google / common / base / Function在T1.main(T1.java:14)造成原因:java.lang.ClassNotFoundException:com.google.common.base.Function在java.net.URLClassLoader.findClass(未知源)在java.lang.ClassLoader.loadClass(未知源)在sun.misc.Launcher $ AppClassLoader.loadClass(未知源)在java.lang.ClassLoader.loadClass(未知源) ...還有1個

在Selenium 3.1.0中,您必須執行以下操作來初始化壁虎驅動程序:

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

Webdriver driver =新的Firefoxdriver();

運行您的代碼。 應該會成功。 讓我知道這是否適合您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM