Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include ChromeDriver in a JAR?

I'm writing a web-automation program and so far, it works fine using Selenium's FirefoxDriver. However, I want to make it use Chrome if Firefox is not installed. I downloaded the ChromeDriver, put it inside a folder in my Eclipse project, and ran it. After I added System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver.exe"); it worked fine. However, when I try to export it (using Eclipse's standard Export). It crashes, I believe because it can't find the ChromeDriver (I think this because exporting it with FirefoxDriver works fine).

I have tried changing the .JAR to a .ZIP in order to look inside, and I see that the driver folder was stripped away, simply putting chromedriver.exe inside the top-level JAR. I tried changing the property to System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); but still crashes.

Does anyone know why the exported JAR is unable to find chromeDriver, despite the fact that I have verified that it is in the JAR?

Thanks, Daniel

like image 618
DaniChan Avatar asked Feb 08 '14 18:02

DaniChan


People also ask

How do I use Selenium chrome jar?

Below are the steps to follow while configuring the chrome setup for Selenium. #1) Check the version of the chrome. #3) Download the chromedriver.exe file for the respective OS and copy that .exe file into your local. #4) The path of the chromedriver (C:\webdriver\chromedriver.exe) will be used in our program.

Where do I put ChromeDriver?

Make sure that the chromedriver.exe file is directly under the PATH you specified, i.e. under C:\chromedriver (or an alternative path). If your zip unpacker created a new folder with a different name inside your specified folder, move the .exe file to that path.


1 Answers

Export your code as jar without the chromedriver. Create a folder ChromeDriver. Place your chromedriver.exe in this folder. Place ChromeDriver folder along with your jar.

Also dont forget to set the System property in the code to

System.setProperty("webdriver.chrome.driver", "ChromeDriver/chromedriver.exe"); 

Please let me know if this works for you.

like image 59
Sighil Avatar answered Sep 22 '22 09:09

Sighil