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

Selenium导入谷歌浏览器配置时executable_path弃用警告问题求助

解决Selenium中executable_path弃用的问题

错误原因

你碰到的DeprecationWarning是因为Selenium 4.x版本起,不再支持通过executable_path参数指定ChromeDriver路径,必须改用Service对象来完成这个配置。

正确修改步骤

  1. 导入Service类:从selenium的Chrome服务模块里导入Service类
  2. 创建Service实例:把ChromeDriver的完整路径传入Service的构造函数
  3. 初始化Chrome驱动:将Service对象传给webdriver.Chrome的service参数,同时保留原有的options配置

修正后的完整代码

from selenium import webdriver
from selenium.webdriver.chrome.service import Service  # 新增导入Service类
from selenium.webdriver.common.keys import Keys

options = webdriver.ChromeOptions() 
# 用原始字符串写法避免转义麻烦,可读性更强
options.add_argument(r"user-data-dir=C:\Users\CharlieWait\AppData\Local\Google\Chrome\User Data")
# 实例化Service对象,传入chromedriver的路径
service = Service(r"C:\Users\CharlieWait\chromedriver.exe")
# 把service和options参数传给Chrome驱动
w = webdriver.Chrome(service=service, options=options)

排查额外问题(如果仍报错)

  • 确认ChromeDriver版本和你的Chrome浏览器版本完全匹配,版本不兼容会直接导致驱动启动失败
  • 检查ChromeDriver的路径是否正确,路径里如果有空格或特殊字符,确保用引号包裹
  • 关闭所有Chrome浏览器窗口后再运行代码,避免进程占用冲突

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 21:25:37