今天使用selenium时遇到如下异常信息:

driver.get('https://www.baidu.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\python3.7.3-install-path\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "D:\python3.7.3-install-path\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "D:\python3.7.3-install-path\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"1902135EC45F5C7A8A0CD69740B466CA","isDefault":true,"type":"default"},"id":1,"name":"","origin":"://"}
(Session info: chrome=70.0.3538.102)
(Driver info: chromedriver=2.6.233026,platform=Windows NT 6.3 x86_64)

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

其原因就是Chrome与chromedriver版本不一致,解决方案:

异常信息中指出我chrome的版本是70.0.3538.102,而chromedriver版本是2.6.233026,明显版本不对应:

解决Chrome与chromedriver版本不一致的问题 随笔 第1张

所以就需要去以下网址下载对应版本的chromedriver:

 http://npm.taobao.org/mirrors/chromedriver/

找到对应版本的chromedriver下载并放在对应python版本的Scripts文件夹下:

解决Chrome与chromedriver版本不一致的问题 随笔 第2张

 

解决Chrome与chromedriver版本不一致的问题 随笔 第3张

 

然后就可以正常驱动打开网页了:

解决Chrome与chromedriver版本不一致的问题 随笔 第4张

 

如有错误,欢迎指正!

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄