驱动谷歌浏览器执行用例时报错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版本相对应的版本。

小伙伴们,强烈安利一波👇:
推荐一款轻便实用的Chrome插件(限时免费下载,赠去广告特权)

以上属个人见解。
❤️希望对您有帮助,您的支持是我创作最大的动力!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值