You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium项目ChromeDriver路径配置报错:无法定位Chrome驱动

解决Selenium中ChromeDriver路径配置问题

问题背景

Chrome版本为118.0.5993.89,配置ChromeDriver路径时找不到chromedriver.exe,仅看到源码类文件,运行代码后触发以下报错:

driver = webdriver.Chrome(service=chrome_service)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
line 45, in __init__
   super().__init__(
line 51, in __init__
   self.service.path = DriverFinder.get_path(self.service, options)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 , line 44, in get_path
   raise NoSuchDriverException(f"Unable to locate or obtain driver for {options.capabilities['browserName']}")
selenium.common.exceptions.NoSuchDriverException: Message: Unable to locate or obtain driver for chrome

尝试配置ChromiumDriver路径后仍报错。


解决方案

1. 下载对应版本的ChromeDriver

Chrome版本与ChromeDriver版本必须严格匹配,你需要下载118.0.5993.89版本的ChromeDriver:

  • 选择对应系统的可执行文件包(Windows选win32版本),不要下载源码压缩包,解压后就能看到chromedriver.exe。

2. 正确配置Driver路径

有两种可靠的配置方式:

方式一:直接指定完整路径

在代码中明确传入chromedriver.exe的绝对路径:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

# 替换为你实际的chromedriver.exe路径
chrome_service = Service(executable_path="C:/Users/xxx/Downloads/chromedriver.exe")
driver = webdriver.Chrome(service=chrome_service)

方式二:加入系统环境变量PATH

将chromedriver.exe所在文件夹添加到系统环境变量PATH中,之后无需指定路径,直接初始化:

from selenium import webdriver

driver = webdriver.Chrome()

3. 避坑提示

  • 不要混淆ChromeDriver与ChromiumDriver:Chrome浏览器对应ChromeDriver,Chromium浏览器对应ChromiumDriver,混用会导致路径匹配失败。
  • 确认下载的是可执行文件包,而非源码包:源码包解压后只有代码文件,没有chromedriver.exe,需重新下载对应版本的可执行版。

内容的提问来源于stack exchange,提问作者Durgesh Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 06:42:24