驱动谷歌浏览器执行用例时报错java.lang.IllegalStateException

驱动谷歌浏览器执行用例时报错信息:java.lang.IllegalStateException

Exception in thread "main" 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:847)
	at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
	at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
	at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
	at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
	at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
	at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
	at Example.main(Example.java:22)

查看报错应该是chromedriver的问题
研究一下之后,发现导入chromedriver的版本不对,需要下载与chrome浏览器版本对应版本的chromedriver,比如我的谷歌浏览器版本为75.0.3770.80,需对应下载75版本的chromedriver。
谷歌浏览器与chromedriver版本的对应关系可查看 Chrome与Chromedriver版本对应表(最新),文件中描述支持浏览器版本信息。

解决办法:下载Chromedriver
从网上下载对应版本的chromedriver之后,里面的内容仅为一个.exe文件,将其解压在chrome的安装目录下(C:\Program Files (x86)\Google\Chrome\Application),然后再配置环境变量。

  1. 进入我的电脑->属性->高级系统设置->环境变量
  2. 修改path在最后面添加 ;C:\Program Files (x86)\Google\Chrome\Application\
  3. OK。安装与配置就到此结束。剩下的就是使用java / python来写代码了。

Tips:
下载chromedriver的时候,一定要下载与你电脑上chrome版本相对应的版本。

你可能感兴趣的:(软件测试)