在 java.lang.NoClassDefFoundError "main"线程中获取异常: com/google/common/base/Function



好的,我正在使用
Eclipse neon 客户端组合-3.1.0-节点.jar 对于火狐浏览器设置 39.0

这是我的代码

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

这是错误

线程"main"中的异常 java.lang.NoClassDefFoundError: com/google/common/base/Function at T1.main(T1.java:12) 由以下原因引起: 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(未知来源) ...1 更多

我已经看到了为番石榴-21.0添加路径的解决方案

但更多的错误

线程"main"中的异常 java.lang.IllegalStateException: 路径 驱动程序可执行文件必须由webdriver.gecko.driver设置。 系统属性;有关更多信息,请参阅 https://github.com/mozilla/geckodriver。最新版本可以是 从 https://github.com/mozilla/geckodriver/releases 下载 com.google.common.base.Preconditions.checkState(Preconditions.java:738) 在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:111) 在 org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38) 在 org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:112) 在 org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:302) 在 org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:312) 在 org.openqa.selenium.firefox.FirefoxDriver.(火狐驱动.java:272) 在 org.openqa.selenium.firefox.FirefoxDriver.(火狐驱动.java:267) 在 org.openqa.selenium.firefox.FirefoxDriver.(火狐驱动.java:263) 在 org.openqa.selenium.firefox.FirefoxDriver.(火狐驱动.java:122) 在T1.main(T1.java:12)

添加代码行后,仍然是客户端组合-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();
}
}

这是错误

线程"main"中的异常 java.lang.NoClassDefFoundError: com/google/common/base/Function at T1.main(T1.java:14) 由以下原因引起: 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(未知来源) ...1 更多

在Selenium 3.1.0中,您必须执行以下操作来初始化壁虎驱动程序:

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

Web驱动程序驱动程序=新的火狐驱动程序();

运行代码。它应该是成功。让我知道这是否适合您。

相关内容

最新更新