Chrome版本122.0.6261.95匹配ChromeDriver失败报错求助
Chrome浏览器版本为122.0.6261.95,但ChromeDriver下载页面仅有122.0.6261.94版本。下载该版本并解压得到chromedriver.exe和Lisence.chromedriver,将这两个文件放入Python文件目录后,运行代码时出现报错:
Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\driver_finder.py", line 38, in get_path
path = SeleniumManager().driver_location(options) if path is None else path
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\selenium_manager.py", line 90, in driver_location
output = self.run(args)
^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\selenium_manager.py", line 138, in run
raise WebDriverException(f"Unsuccessful command executed: {command}.\n{result}{stderr}")
selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome --output json.
{'code': 69, 'message': 'Driver unavailable: Driver path: ', 'driver_path': '', 'browser_path': ''}上述异常直接导致以下异常:
Traceback (most recent call last):
File "c:\Users\user\Desktop\�꒵����\��ũ�Ѹ�\insta\app.py", line 6, in
driver = webdriver.Chrome()
^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in init
super().init(
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\chromium\webdriver.py", line 51, in init
self.service.path = DriverFinder.get_path(self.service, options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\driver_finder.py", line 41, in get_path
raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.
需要找到匹配Chrome版本的ChromeDriver并解决问题。
- Selenium Manager默认会自动检测Chrome版本并匹配对应ChromeDriver,但你的Chrome版本(122.0.6261.95)比公开可下载的ChromeDriver版本(122.0.6261.94)高一个小版本,导致Selenium Manager无法识别手动放置的驱动,仍尝试自动下载匹配版本但失败。
- 手动放置的驱动路径未被Selenium正确识别:Python文件目录可能不在系统环境变量中,或者Selenium优先调用Selenium Manager而非手动指定的驱动。
方法一:手动指定ChromeDriver路径
初始化WebDriver时,明确指定chromedriver.exe的实际路径,跳过Selenium Manager的自动检测逻辑:
from selenium import webdriver from selenium.webdriver.chrome.service import Service # 替换为你的chromedriver.exe所在的实际路径 service = Service(executable_path=r"C:\xxx\chromedriver.exe") driver = webdriver.Chrome(service=service)
方法二:降级Chrome浏览器到匹配版本
将Chrome降级至122.0.6261.94版本,确保与现有ChromeDriver版本完全匹配:
- 卸载当前Chrome浏览器
- 下载对应版本的Chrome离线安装包完成安装,同时关闭Chrome自动更新功能,避免再次升级
方法三:使用对应通道的ChromeDriver
如果不想降级Chrome,可以查看Chrome Beta/Dev通道的驱动下载页,这类通道的驱动更新通常更及时,可能会有匹配122.0.6261.95版本的ChromeDriver。
方法四:配置系统环境变量
将存放chromedriver.exe的文件夹路径添加到系统环境变量PATH中,让Selenium能自动检索到驱动:
- 右键「此电脑」→「属性」→「高级系统设置」→「环境变量」
- 在系统变量的
PATH中添加chromedriver.exe所在的文件夹路径 - 重启命令行或开发工具后重新运行代码
内容的提问来源于stack exchange,提问作者user23516681

