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

Ashish Deshmukh
  • 448
  • 4
  • 17
Lipson T A
  • 49
  • 3
  • 9
  • "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" – Lipson T A Aug 10 '17 at 15:03
  • I tried all the methods in the thread..But its not solved yet – Lipson T A Aug 10 '17 at 15:11
  • are these jars set properly in your classpath? – robot_alien Aug 10 '17 at 15:25
  • It might be helpful to upload screen shot, your project preference of classpath – sayingu Aug 10 '17 at 16:09
  • Your POM reference and which version of Firefox are you using? – Tarun Lalwani Aug 10 '17 at 20:42
  • System.setProperty("webdriver.gecko.driver",//E://share//geckodriver.exe"); This code is not correct – iamsankalp89 Aug 11 '17 at 05:42
  • Its a simple project using eclipse.Not created as a maven project. Firefox version - 52.2.1 – Lipson T A Aug 11 '17 at 14:54

1 Answers1

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");
        }
    }
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352