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

Chrome与ChromeDriver版本匹配但Selenium无法运行的问题求助

解决Selenium初始化Chrome驱动的AttributeError问题

错误原因

你直接把ChromeDriver路径作为参数传给webdriver.Chrome(),但Selenium 4及以上版本中,这个位置需要传入ChromeOptions对象,而非字符串路径,这就触发了'str' object has no attribute 'capabilities'错误。

正确实现方式

方式1:通过Service类指定驱动路径

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

# 替换为你的ChromeDriver实际路径
driver_path = 'C:/Users/[...]/chromedriver/chromedriver.exe'
service = Service(driver_path)
driver = webdriver.Chrome(service=service)
driver.get("https://www.google.com")

方式2:让Selenium自动管理驱动(推荐)

Selenium 4.6+版本自带Selenium Manager,会自动匹配对应版本的ChromeDriver,无需手动下载配置:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.google.com")

额外检查项

  • 你的Chrome(119.0.6045.200)和ChromeDriver(119.0.6045.105)主版本号一致,这部分没问题
  • 手动指定路径时,确认路径拼写正确,Windows路径可使用正斜杠/或双反斜杠\\

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 06:42:36