Mac 下载/安装 ChromeDriver 高版本,解决报错 “This version of ChromeDriver only supports Chrome version xxx“

本文讲述了在使用Python的Selenium时遇到的版本不兼容问题,如何通过检查Chrome版本并下载对应高版本ChromeDriver来解决SessionNotCreatedException。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


1. 问题

当你运行 python 的 selenium 包,报错如下:

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 120.0.6099.199 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

说明 ChromeDriver 和你的 Chrome 浏览器版本不匹配!但是网上的 下载链接 截止到2024-1-4只到 114.0.5735.90 版本,此时我的浏览器已经是120打头的了!

如果你也是上述这个情况,那么可以接着往下看!
在这里插入图片描述

2. 解决方法

2.1 查看 Chrome 版本

以我的浏览器为例:
在这里插入图片描述
在这里插入图片描述
我的版本是120.0.6099.129,在这个 下载链接 找不到对应的版本。

2.2 下载高版本的 ChromeDriver

此时你应该用这个下载链接 高版本点击这里
在这里插入图片描述
点击对应的链接,网页转到如下:
在这里插入图片描述
选择你的电脑匹配的版本下载 ChromeDriver!

3. 参考

chrome driver下载、selenium安装及报错解决

"D:\Program Files\python\python.exe" D:\pcWJ\测试项目\cs.py The chromedriver version (101.0.4951.41) detected in PATH at D:\download\火狐下载\chromedriver.exe might not be compatible with the detected chrome version (134.0.6998.178); currently, chromedriver 134.0.6998.165 is recommended for chrome 134.*, so it is advised to delete the driver in PATH and retry Traceback (most recent call last): File "D:\pcWJ\测试项目\cs.py", line 5, in <module> driver = webdriver.Chrome() ^^^^^^^^^^^^^^^^^^ File "D:\Program Files\python\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__ super().__init__( File "D:\Program Files\python\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 66, in __init__ super().__init__(command_executor=executor, options=options) File "D:\Program Files\python\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 250, in __init__ self.start_session(capabilities) File "D:\Program Files\python\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 342, in start_session response = self.execute(Command.NEW_SESSION, caps)["value"] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Program Files\python\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 429, in execute self.error_handler.check_response(response) File "D:\Program Files\python\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 232, 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 101 Current browser version is 134.0.6998.178 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe Stacktrace: Backtrace: Ordinal0 [0x00F1B8F3+2406643] Ordinal0 [0x00EAAF31+1945393] Ordinal0 [0x00D9C748+837448] Ordinal0 [0x00DBC8B3+968883] Ordinal0 [0x00DB84BA+951482] Ordinal0 [0x00DB5D71+941
04-02
### 如何下载安装适用于Chrome的WebDriver #### 下载 WebDriver 为了获取适合操作系统的 Chrome WebDriver,可以前往指定的下载仓库进行下载。该仓库提供了针对不同操作系统(Windows、Mac 和 Linux)的最新版本驱动程序[^1]。 - **项目地址**: [https://gitcode.com/open-source-toolkit/c740a](https://gitcode.com/open-source-toolkit/c740a) 在进入上述链接后,选择与您的操作系统匹配的 `win64` 或其他对应平台版本的压缩包并下载。 --- #### 安装步骤说明 一旦完成下载,需按照以下方式配置环境: 1. 解压已下载的 `.zip` 文件,从中提取名为 `chromedriver.exe` 的可执行文件。 2. 将此文件放置于 Python 的根目录下,具体位置应为包含 `python.exe` 的同一级目录中[^2]。 3. 更新系统 PATH 环境变量以包含 `chromedriver.exe` 所处的具体路径。这一步确保命令行工具能够全局识别该驱动器。 通过以上设置完成后,可以通过运行一段简单的 Selenium 测试脚本来验证安装是否成功: ```python from selenium import webdriver browser = webdriver.Chrome() browser.get('https://www.baidu.com/') ``` 如果一切正常,在执行这段代码之后会自动打开 Google Chrome 并跳转至百度首页,则表明 WebDriver 已经正确安装。 --- #### 版本兼容性注意事项 需要注意的是,Selenium 使用的 ChromeDriver 需要与其所控制的 Chrome 浏览器保持版本一致。例如,当遇到错误提示类似于 `selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version xxx` 时,这意味着当前使用的 ChromeDriver 不支持现有的浏览器版本[^3]。此时应当重新确认本地 Chrome 浏览器的实际版本号,并据此选取相适应的 ChromeDriver 发布版来替换旧有版本。 --- #### 常见问题排查 假如仍然无法正常使用,请检查以下几个方面: - 是否准确无误地设置了环境变量; - 当前计算机上的 Chrome 浏览器版本是否过期或者超前于可用的 ChromeDriver 支持范围之外; - 如果存在多个版本的 `chromedriver.exe` 存在于不同的路径里,可能引起冲突,建议清理多余的副本只保留一个最新的有效版本。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SmallerFL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值