解决:利用pycharm编写脚本实现自动化测试时出现驱动版本不匹配问题

本文讲述了在Python中遇到ChromeDriver与Chrome浏览器版本不兼容的问题,提供了检查浏览器版本、下载对应Chromedriver、更新代码路径以及使用Service对象的方法,同时提醒读者注意Selenium插件的版本选择。
摘要由CSDN通过智能技术生成

报错内容:问题在于使用的 ChromeDriver 版本与 Chrome 浏览器版本不兼容。

Traceback (most recent call last): File "C:\Users\86137\PycharmProjects\Supermarket\zhuce.py", line 6, in <module> driver = webdriver.Chrome() ^^^^^^^^^^^^^^^^^^ File "C:\Users\86137\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 84, in __init__ super().__init__( File "C:\Users\86137\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 104, in __init__ super().__init__( File "C:\Users\86137\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 286, in __init__ self.start_session(capabilities, browser_profile) File "C:\Users\86137\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 378, in start_session response = self.execute(Command.NEW_SESSION, parameters) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\86137\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute self.error_handler.check_response(response) File "C:\Users\86137\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 113 Current browser version is 124.0.6367.119 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe Stacktrace: Backtrace:

1.可以在Chrome浏览器设置中查看自己的Chrome版本,然后去https://getwebdriver.com/chromedriver下载对应的Chrome driver版本。

2.将下载的 ChromeDriver 可执行文件放置到您的系统路径中,或者在代码中指定其路径。

3.更新您的代码中的 chromedriver_path 变量,指向新的 ChromeDriver 可执行文件的位置

chromedriver_path = r"C:\路径\到\新下载的\chromedriver.exe"

driver = webdriver.Chrome(executable_path=chromedriver_path)

如果上面代码运行出现以下报错:

DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome(executable_path=chromedriver_path)

则可以使用 Service 对象来指定 ChromeDriver 的路径

from selenium import webdriver

from selenium.webdriver.chrome.service import Service

# 指定ChromeDriver的路径

chromedriver_path = r"C:\路径\到\chromedriver.exe"

# 创建Service对象

service = Service(executable_path=chromedriver_path)

# 初始化WebDriver,传入Service对象

driver = webdriver.Chrome(service=service)

同时需要下载selenium插件实现自己的测试,可以下载最新版本也可以下载4.9.0版本。

  • 46
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值