java.lang.NoClassDefFoundError:com / google / common / base / Function [英] java.lang.NoClassDefFoundError: com/google/common/base/Function

查看:123
本文介绍了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:


  1. 当您的代码位于 Java System.setProperty 行期望 value 字段包含单个正斜杠 / 或反斜杠 \\

  2. 参数需要作为 String 传递给双引号 ...

  3. 如果您正在使用 DesiredCapabilities 类,请记住传递 DesiredCapabilities 在启动 WebDriver 实例时将类作为参数。

  4. 如果使用的是 import org.openqa .selenium.remote。*; 确保已添加最新的 selenium-server-standalone.jar 作为外部Jar

  5. 启动浏览器会话后,导航至某个网址以确认是否建立了成功的会话。

  6. 您的最终代码块将如下所示:

  1. When your code is in Java, System.setProperty line expects the value field to contain either single forward slashes / or escaped backward slashes \\.
  2. The value parameter needs to to be passed as a String within double quotes "..."
  3. If you are using DesiredCapabilities Class, remember to pass the instance of the DesiredCapabilities Class as an argument when you initiate the WebDriver instance.
  4. If you are using import org.openqa.selenium.remote.*; ensure that you have added the latest selenium-server-standalone.jar as an External Jar.
  5. Once you initiate a browser session navigate to some url to confirm if a successful session is established.
  6. 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆