When i am trying to invoke chrome browser in eclipse using selenium driver with Java , i am getting an error.
Please help me out in resolving this issue.
Below is my code -
package packagedefault;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeBrowser {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://google.com");
}
}
Below is the error message i am getting -
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/config/RegistryBuilder
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:69)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:57)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:60)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:242)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.<init>(ApacheHttpClient.java:219)
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:63)
at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.<init>(ChromeDriverCommandExecutor.java:36)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at packagedefault.ChromeBrowser.main(ChromeBrowser.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.config.RegistryBuilder
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
You can try using below code inside main() function
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");
Works properly here in my windows PC
Exception you mentioned
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/http/config/RegistryBuilder
Occured when jars files are not available.
Import only the selenium-server-standalone- jars and try your code .
System.setProperty("webdriver.chrome.driver", "Path of chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://google.com");
Related
I have basic file and running the java file, throws No classDeffoundError: io/netty/util/Timer at
packkage cucumber ;
public class seleniumTesting{
System.setproperty("webdriver.chrome.driver", ".\\downloads\chromedriver.exe");
WebDriver driver = new Chromedriver();
please suggest where is the issue.
This question already has answers here:
java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap error using GeckoDriver Firefox through Selenium in Java
(1 answer)
Selenium Webdriver + Java - Eclipse: java.lang.NoClassDefFoundError
(7 answers)
Closed 2 years ago.
Hi i'm rather new to selenium and understand the basics but cant understand why my basic code it just open a web page is throwing the error its throwing. The error its throwing ill be listed at the bottom.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Selenium1 {
public static void main(String[] args) {
WebDriver Driver = new ChromeDriver ();
String web = "https://www.facebook.com/";
Driver.get(web);
System.out.println(Driver.getTitle());
}
}
Exception in thread "main" java.lang.NoClassDefFoundError:
com/google/common/collect/ImmutableMap at
org.openqa.selenium.remote.service.DriverService$Builder.(DriverService.java:259)
at
org.openqa.selenium.chrome.ChromeDriverService$Builder.(ChromeDriverService.java:101)
at
org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at Selenium1.main(Selenium1.java:10) Caused by:
java.lang.ClassNotFoundException:
com.google.common.collect.ImmutableMap at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 5 more
Not Able to open Chrome browser in Selenium.
Here is the code:
package toolsqa;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestChrome {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\MR049860\\Documents\\Selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
}
}
I'm getting the following Exception:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at toolsqa.TestChrome.main(TestChrome.java:14)
The error says it all :
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
While mentioning the Key and Value within System.setProperty() you have to escape the back slashes (\\). Hence, you need to change the line :
System.setProperty("webdriver.chrome.driver","C:Path\chromedriver.exe");
To :
System.setProperty("webdriver.chrome.driver","C:\\absolute_path\\to\\chromedriver.exe");
I'm trying to run selenium webdriver program, getting following error :
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.io.FileHandler.unzip(Ljava/io/InputStream;)Ljava/io/File;
Firefox version : 47.0.1
Selenium version : 2.53.1
Eclipse : Oxygen Release (4.7.0)
import org.apache.xpath.XPathContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PG1
{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://demo.guru99.com/selenium/newtours/");
System.out.println("The title of page is : " + driver.getTitle());
driver.close();
}
}
This program was working fine in another laptop, but not working on new laptop/setup.
Can someone please help.
Error I'm getting :
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.io.FileHandler.unzip(Ljava/io/InputStream;)Ljava/io/File;
at org.openqa.selenium.firefox.internal.FileExtension.obtainRootDirectory(FileExtension.java:82)
at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:59)
at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:64)
at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:443)
at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:421)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:85)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.startClient(RemoteWebDriver.java:303)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:125)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at bitbfw.PG1.main(PG1.java:11)
Found what was wrong..
it was that in "Java Build Path", the JRE system library was not added earlier. I went to configure Build path-->Add Jars selected "jRE system library", Applied & Closed.
Then on all the programs worked fine.
I am running simple code in selenium and it throws below exception:-
#Test
public void test(){
System.setProperty("webdriver.chrome.driver", "geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://google.com");
driver.manage().window().maximize();
}
Following error is shown when I have executed my script:
Previously it was working, my firefox version is 55 and i am using latest gecko driver version. Please help!!
Exception is:-
java.lang.NoSuchMethodError:
com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
at
org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at
org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:41)
at
org.openqa.selenium.firefox.GeckoDriverService$Builder.usingFirefoxBinary(GeckoDriverService.java:108)
at
org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:204)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:103)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:99)
at newTab.Tab.test(Tab.java:16) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:645) at
org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851) at
org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177) at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756) at
org.testng.TestRunner.run(TestRunner.java:610) at
org.testng.SuiteRunner.runTest(SuiteRunner.java:387) at
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382) at
org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at
org.testng.SuiteRunner.run(SuiteRunner.java:289) at
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at
org.testng.TestNG.runSuitesSequentially(TestNG.java:1293) at
org.testng.TestNG.runSuitesLocally(TestNG.java:1218) at
org.testng.TestNG.runSuites(TestNG.java:1133) at
org.testng.TestNG.run(TestNG.java:1104) at
org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
You are using wrong syntax near "System.setProperty("webdriver.chrome.driver", "geckodriver.exe");". Replace "chrome.driver" with "gecko.driver"
#Test public void test(){
System.setProperty("webdriver.chrome.driver", "geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://google.com");
driver.manage().window().maximize();
}
Replace it with
#Test public void test(){
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://google.com");
driver.manage().window().maximize();
}
The error
Exception is:- java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V at
is Java's way of telling you that your code is internally invoking a method called
void checkState(boolean, java.lang.String, java.lang.Object)
within the class com.google.common.base.Preconditions but this method is not available.
This usually happens when your classpath is messed up.
You haven't mentioned what version of Selenium you are working with. So I am going to assume that you are working with the latest released version of Selenium viz., 3.5.2.
Please make sure that you are using com.google.guava:guava version 23.0.
If you are using Maven, then you can perhaps add a dependency which looks like below, to your pom file.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
it's conflict problem, you should check on Project Structure, if it exists 2 Maven, it's conflict problem, you have to delete "Maven: com.google.guava: guava:jdk...". If it exists only 1 Maven guava, just need update the dependency