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

Selenium调用ChromeDriver报NoSuchDriverException问题求助

错误原因

直接将ChromeDriver路径字符串传入webdriver.Chrome()是错误用法。Selenium 4及以上版本中,webdriver.Chrome()的第一个参数是浏览器配置选项(options),而非驱动路径。你传入的字符串被识别为options对象,因此触发'str' object has no attribute 'capabilities'错误。

另外从路径截图来看,你指定的路径是文件夹(chromedriver_win32),但实际需要指向具体的chromedriver.exe可执行文件。

解决方法

提供两种可行方案:

方案1:使用Service类指定驱动路径

导入ChromeService,将驱动路径传入Service实例,再将Service传给webdriver.Chrome():

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

url = "https://google.com/"
# 路径需指向具体的chromedriver.exe,而非文件夹
path = "C:/Users/thefo/OneDrive/Desktop/summer 2023/chromedriver_win32/chromedriver.exe"

service = Service(path)
driver = webdriver.Chrome(service=service)
driver.get(url)

方案2:让Selenium自动管理ChromeDriver(推荐)

Selenium 4.6+版本自带Selenium Manager,会自动下载匹配Chrome浏览器版本的驱动,无需手动指定路径:

from selenium import webdriver

url = "https://google.com/"

# 无需手动指定驱动路径,Selenium自动处理
driver = webdriver.Chrome()
driver.get(url)
额外注意事项
  • 若手动指定驱动路径,需确保Chrome浏览器版本与ChromeDriver版本完全匹配
  • 手动指定路径时,必须指向chromedriver.exe可执行文件,不能只写文件夹路径

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 21:30:15