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

Python中使用Selenium WebDriver报错:'str'对象无'capabilities'属性求解决

解决Selenium初始化时的'str' object has no attribute 'capabilities'错误

这个错误是因为Selenium 4.x及以上版本调整了webdriver.Chrome()的参数规则,不再支持直接传入字符串类型的驱动路径作为第一个参数。以下是两种正确的初始化方式:

方式一:手动指定驱动路径

需要借助selenium.webdriver.chrome.service.Service类封装驱动路径:

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

# 替换为你的Chrome驱动实际本地路径
driver_path = "/your/path/to/chromedriver"
service = Service(driver_path)
driver = webdriver.Chrome(service=service)

方式二:用ChromeDriverManager自动管理驱动

同样需要结合Service类使用:

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

service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)

额外注意

如果你的Selenium版本低于4.x,建议升级到最新版本:

pip install --upgrade selenium

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 17:22:01