我的代码很简单
代码:
WebDriver wd =new ChromeDriver();
System.setProperty("webdriver.chrome.driver",
"D:\\List_of_Jar\\chromedriver.exe");
String baseUrl = "https://www.google.com";wd.get(baseUrl);
已从 selenium hq 站点下载并添加 jar 为“Java-3.4.0”。从同一网站下载 Google Chrome Driver-2.29 并将其放置在“D:\List_of_Jar”路径中。
当我运行上面的代码时,我得到一个错误
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:738)
尽管进行了正确的配置,但出现版本错误。所以请帮我解决这个问题。细节:
最佳答案
我完全同意 Murthi,但更好的是设置驱动程序的相对路径,而不是绝对路径。
相对路径如下:
System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver.exe");
Abosulte:是您 PC 中驱动程序的路径。
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
为什么?
在您的项目中包含驱动程序是一个很好的做法,而不仅仅是在您的计算机中。只需找到或创建文件夹 f.e.资源,在资源内部创建名为 f.e. 的文件夹驱动程序并在那里导入您的驱动程序/驱动程序 exe 文件。
关于selenium - 通过设置正确的路径获取 "The path to the driver executable must be set by the webdriver.chrome.driver system property",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44476647/