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

Selenium运行提示executable_path已弃用报错的解决方法咨询

报错原因
  • Selenium 4.6及以上版本正式废弃了executable_path参数,不再支持直接将驱动路径传入webdriver.Chrome(),要求通过Service对象传递驱动配置信息
  • 你的路径配置本身存在两处平台适配错误:
    1. MacOS系统不需要.exe后缀的驱动文件,.exe是Windows平台的可执行文件格式,你需要下载对应Mac架构的ChromeDriver文件,文件本身无后缀
    2. MacOS不存在C盘盘符,路径分隔符使用正斜杠/,你写的C:前缀、路径内的反斜杠\都是Windows系统的规则,不适配Mac环境
解决方法

方案一:手动指定驱动路径(适配旧用法习惯)

  1. 先下载和本地Chrome浏览器大版本一致的Mac版ChromeDriver,解压后放置到对应目录,修正后的路径示例为/Users/blutch/Documents/Chrome Web Driver/chromedriver
  2. 调整代码,引入Service类传入驱动配置,代码示例:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

# 路径全部使用正斜杠,不要加.exe后缀
PATH = '/Users/blutch/Documents/Chrome Web Driver/chromedriver'
service = Service(executable_path=PATH)
driver = webdriver.Chrome(service=service)
driver.get("https://www.google.com")
  1. 如果运行时弹出Mac无法验证开发者的权限提示,打开终端执行授权命令:
    xattr -d com.apple.quarantine /Users/blutch/Documents/Chrome\ Web\ Driver/chromedriver
    (注:路径中的空格前需要加反斜杠\转义,也可以将整个路径用双引号包裹)

方案二:使用内置自动管理功能(更简便)

Selenium 4.6及以上版本内置了Selenium Manager,无需手动下载ChromeDriver、配置路径,直接简化代码即可运行:

from selenium import webdriver

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

运行时会自动匹配下载和当前Chrome版本适配的驱动,无需手动做任何配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 17:15:03