1

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.

I am using JDK 1.8 and eclipse neon for writing the code.

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

}

Error is

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

7
  • "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" Commented Aug 10, 2017 at 15:03
  • I tried all the methods in the thread..But its not solved yet Commented Aug 10, 2017 at 15:11
  • are these jars set properly in your classpath? Commented Aug 10, 2017 at 15:25
  • It might be helpful to upload screen shot, your project preference of classpath Commented Aug 10, 2017 at 16:09
  • Your POM reference and which version of Firefox are you using? Commented Aug 10, 2017 at 20:42

1 Answer 1

1

You need to take care of lot of things in your code as follows:

  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");
        }
    }
    
Sign up to request clarification or add additional context in comments.

1 Comment

@LipsonTA Check my updated answer and let me know the status.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.