今天学习selenium,利用ide生成的脚本放到idea去跑,报错
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
翻译过来,就是提示我需要chrome.driver。打开他提示我的网址
http://chromedriver.storage.googleapis.com/index.html
对照我谷歌的版本,查看版本路径右上角三个点-帮助-关于Google。
找到一样的版本,如果没有一样的,找相近的也行。我是107.0.5304.88,但是没有这个版本的,我就下载了107.0.5304.62的。
下载下来后,放在自己知道的文件夹下,或者直接放在java项目文件夹里,在setUp中添加System.setProperty
@Before
public void setUp() {
Sting src="src/main/resources/chromedriver.exe"; //chromedriver目录,绝对/相对路径
System.setProperty("webdriver.chrome.driver",src);
driver = new ChromeDriver();
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
正常运行。