![](/img/trans.png)
[英]Exception in thread “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.