Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set relative path for selenium web driver

I create chrome driver like this:

System.setProperty("webdriver.chrome.driver",
            "C:\\Users\\ragnar_000\\IdeaProjects\\ProjectA\\src\\test\\resources\\chromedriver.exe");
webDriver = new ChromeDriver();

This code is written on Windows platform. When I run it on Mac, I have to edit the path according to Mac platform.

How to set/check the path so that it can run on all platforms, like it just needs the path src/test/resources/chromedrivers.exe

like image 614
Ragnarsson Avatar asked Nov 18 '25 08:11

Ragnarsson


1 Answers

Create a folder under your project and copy the chromedriver.exe to that folder (eg: /resources/chromedrivers.exe).

Then set the path to that folder by

String path = System.getProperty("user.dir");
System.out.println(path); 
System.setProperty("webdriver.chrome.driver",path+"\\resources\\chromedriver.exe");

I have tried in windows and its working.Try if it works on Mac.

like image 73
Sijin Avatar answered Nov 20 '25 21:11

Sijin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!