Reputation: 49
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
Upvotes: 1
Views: 6323
Reputation: 193078
You need to take care of lot of things in your code as follows:
Java
, System.setProperty
line expects the value
field to contain either single forward slashes /
or escaped backward slashes \\
.value
parameter needs to to be passed as a String
within double quotes "..."
DesiredCapabilities
Class, remember to pass the instance of the DesiredCapabilities
Class as an argument when you initiate the WebDriver
instance.import org.openqa.selenium.remote.*;
ensure that you have added the latest selenium-server-standalone.jar
as an External Jar
.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");
}
}
Upvotes: 1