java.lang.IllegalStateException:驱动程序可执行文件不存在:带有ChromeDriver的C:\ Users \ jagrelot \ workspace \ AntBuildExample \ chromedriver.exe [英] java.lang.IllegalStateException: The driver executable does not exist: C:\Users\jagrelot\workspace\AntBuildExample\chromedriver.exe with ChromeDriver
问题描述
当我尝试在Eclipse中运行Selenium时,出现驱动程序可执行文件不存在:错误".我确保exe的路径正确,并且已设置环境PATH变量.错误是指驱动程序的旧位置,该位置位于Java项目的工作空间中.当我通过命令行运行它时,它似乎正在工作.有什么建议可以使代码正确地在Eclipse中运行?
When I try to run Selenium within Eclipse, I get a The driver executable does not exist: error. I've ensured that the path to the exe is correct and that the environment PATH variable is set. The error is referencing an older location of the driver which was located in the workspace of the Java project. It seems to be working when I run it through the command line. Are there any suggestions to get the code to run in Eclipse properly?
public WebDriver chromeDriver;
@BeforeTest
public void beforeTestsetUp(){
System.setProperty("webdriver.chrome.driver", "C:\\Driver\\chromedriver.exe");
chromeDriver = new ChromeDriver();
[RemoteTestNG] detected TestNG version 6.12.0
FAILED CONFIGURATION: @BeforeTest beforeTestsetUp
java.lang.IllegalStateException: The driver executable does not exist: C:\Users\jagrelot\workspace\AntBuildExample\chromedriver.exe
推荐答案
您提供的代码块不足以分析根本原因.以下几点几乎是显而易见的:
The code block you have provided is not sufficient to analyze the root cause. How ever the following points are pretty much evident :
-
ChromeDriver
的初始化容易出错,应该是:
The initialization of
ChromeDriver
is error prone, it should have been :
ChromeDriver driver = new ChromeDriver();
根据最佳实践,我们应该使用 WebDriver
接口而不是 ChromeDriver
实现:
As per best practices we should use the WebDriver
interface instead of the ChromeDriver
implementation :
WebDriver driver = new ChromeDriver();
您看到的错误为 IllegalStateException: The driver executable does not exist: C:\Users\jagrelot\workspace\AntBuildExample\chromedriver.exe
,它清楚地表明您的脚本正在除以下位置之外的其他位置查找 chromedriver
二进制文件提到一个.可能是由于 setProperty
的error prone
代码造成的.
As you are seeing the error as IllegalStateException: The driver executable does not exist: C:\Users\jagrelot\workspace\AntBuildExample\chromedriver.exe
which clearly indicates your script is looking for the chromedriver
binary in a different location other than the mentioned one. Probably its due to error prone
code of setProperty
.
这篇关于java.lang.IllegalStateException:驱动程序可执行文件不存在:带有ChromeDriver的C:\ Users \ jagrelot \ workspace \ AntBuildExample \ chromedriver.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!