java.lang.NoClassDefFoundError:com / google / common / base / Function [英] java.lang.NoClassDefFoundError: com/google/common/base/Function
问题描述
我是Selenium Web驱动程序的初学者。致电driver时遇到一些问题。我附上了程序和错误,供您参考。
1)我已经尝试使用独立jar和单个jar文件
2)在环境变量中也正确设置了路径。
I am a beginner in Selenium web driver. I am getting some issues while calling driver.I am attaching the program and error for your reference. 1) I have already tried with standalone jar and individual jar files 2) Path also set correctly in environment variables.
我正在使用JDK
如果可以的话,请帮帮我。尝试了互联网上提到的很多方法。仍然无法确定是什么确切的问题。当我创建一个Testng示例程序时,就会在特定的一天抛出该错误。
Please help me if you can..Tried so many ways which is mentioned on internet.Still couldn't identify what is the exact issue. This error started to throw on a particular day when I created a Testng sample program.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Sample22 {
public static void main(String[] args) { System.setProperty("webdriver.gecko.driver",//E://share//geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
//WebDriver driver1 = new MarionetteDriver(capabilities);
WebDriver driver1 = new FirefoxDriver();
}
}
错误为
线程 main中的异常java.lang.NoClassDefFoundError:com / google / common / base / Function在Sample22.main(Sample22。 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 java.lang .ClassLoader.loadClass(Unknown Source)...另外1个
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function at Sample22.main(Sample22.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 java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more
推荐答案
照顾你很多事情r代码如下:
You need to take care of lot of things in your code as follows:
- 当您的代码位于
Java
,System.setProperty
行期望value
字段包含单个正斜杠/
或反斜杠\\
。 -
值
参数需要作为String
传递给双引号...
- 如果您正在使用
DesiredCapabilities
类,请记住传递DesiredCapabilities
在启动WebDriver
实例时将类作为参数。 - 如果使用的是
import org.openqa .selenium.remote。*;
确保已添加最新的selenium-server-standalone.jar
作为外部Jar
。 - 启动浏览器会话后,导航至某个网址以确认是否建立了成功的会话。
-
您的最终代码块将如下所示:
- When your code is in
Java
,System.setProperty
line expects thevalue
field to contain either single forward slashes/
or escaped backward slashes\\
. - The
value
parameter needs to to be passed as aString
within double quotes"..."
- If you are using
DesiredCapabilities
Class, remember to pass the instance of theDesiredCapabilities
Class as an argument when you initiate theWebDriver
instance. - If you are using
import org.openqa.selenium.remote.*;
ensure that you have added the latestselenium-server-standalone.jar
as anExternal Jar
. - Once you initiate a browser session navigate to some url to confirm if a successful session is established.
Your final code block will look like:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Sample22
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "E:\\share\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
driver.navigate().to("https://google.com");
}
}
这篇关于java.lang.NoClassDefFoundError:com / google / common / base / Function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!