我知道这个问题已经被问过多次了。但是,我找不到任何答案。
这是我正在使用的东西的一些细节。
Firefox版本-63.0
硒-selenium-java-3.14
我的示例代码-
import java.util.concurrent.TimeUnit;
导入org.openqa.selenium.WebDriver; 导入org.openqa.selenium.firefox.FirefoxDriver;
公共类webdriverdemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
String projectLocation = System.getProperty("user.dir");
System.setProperty("webdriver.gecko.driver","E:\\Proffessional\\FMClarity\\Selenium\\gecko\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//Puts an Implicit wait, Will wait for 10 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch website
driver.navigate().to("http://www.calculator.net/");
}
}
但是,我遇到了以下错误。
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
at org.openqa.selenium.remote.service.DriverService$Builder.<init>(DriverService.java:250)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.<init>(GeckoDriverService.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:164)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:103)
at webdriverdemo.main(webdriverdemo.java:13)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
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)
... 6 more
我的路径是这样给出的。
有人可以告诉我该怎么办才能解决此错误。
预先感谢
答案 0 :(得分:0)
我已将jar文件用于2.53.1。问题解决了。
答案 1 :(得分:-1)
问题是您的代码中没有gico-driver
尝试
public static void main(String[] args) {
// TODO Auto-generated method stub
//complete path to your project
String projectLocation = System.getProperty("user.dir");
System.setProperty("webdriver.gecko.driver",your driver full path);
WebDriver driver = new FirefoxDriver();
//Puts an Implicit wait, Will wait for 10 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch website
driver.navigate().to("http://www.calculator.net/");
}