I want to set as system property a file path from resources folder.
String path = MainCore.class.getClassLoader().getResource("chromedriver-76.0.3809.68.exe").toExternalForm();
System.out.println(path);
//file:/D:/JavaIDEA/projname/target/classes/chromedriver-76.0.3809.68.exe
System.setProperty("webdriver.chrome.driver", path);
//IllegalStateException: The driver executable does not exist:
//D:\JavaIDEA\projname\file:\D:\JavaIDEA\projname\target\classes\chromedriver-76.0.3809.68.exe
Why when I setProperty
, it add in front of my path the path of project?
I also tried this: path = path.replace("/", "\\\\\\\\");
- same result
I'm using Windows.
Try
String absolutePath = new File(MainCore.class.getClassLoader().getResource("chromedriver-76.0.3809.68.exe").getFile()).getAbsolutePath();
System.setProperty("webdriver.chrome.driver", path);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.