How to read the maven dependecy of chrome browser which is a .jar file into my java file

1.6k views Asked by At

I'm trying to run my simple Selenium code to open http://google.com on my Chrome browser. I am using Selenium 3.0.

I have a maven dependency in my POM.xml for chromedriver which is as follows:

<dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-chrome-driver</artifactId>
   <version>2.44.0</version>
</dependency>

Now after giving that dependency I'm able to see selenium-chrome-driver-2.44.0.jar file under my Maven Maven Dependencies folder. However I don't know how to use this jar file to access the chrome browser.

I've tried this:

System.setProperty("webdriver.chrome.driver","C:\\Users\\vikas.kumar5\\.m2\\repository\\org\\seleniumhq\\selenium\\selenium-chrome-driver\\2.44.0\\selenium-chrome-driver-2.44.0.jar");     
WebDriver driver=new ChromeDriver();

I am getting the following exception.

SEVERE: org.apache.commons.exec.ExecuteException: Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "C:\Users\vikas.kumar5.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\2.44.0\selenium-chrome-driver-2.44.0.jar" (in directory "."): CreateProcess error=193, %1 is not a valid Win32 application) Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700' System info: host: 'HOME', ip: '192.168.56.1', os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.8.0_60' Driver info: driver.version: ChromeDriver at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:178)

Can anyone tell me how can I run my selenium code on Chrome browser (without using the chromedriver.exe file) ?

I want to know how we can run selenium code on chrome using dependencies ?

1

There are 1 answers

0
Saurav On BEST ANSWER

You should remove the Chrome dependency from the pom.xml file and instead initialize the webdriver using below code : System.setProperty("webdriver.chrome.driver","C:\\Users\\chromedriver.exe");
WebDriver driver=new ChromeDriver();

You can download ther latest Chrome driver from http://www.seleniumhq.org/download .