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

Selenium Python报错:WebDriver.__init__()收到意外关键字参数executable_path

问题解决:WebDriver.init() 收到意外关键字参数 'executable_path'

错误原因

Selenium 4.x 及以上版本已移除 webdriver.Chrome() 方法中的 executable_path 参数,该功能改由 Service 类实现。

修改后的代码

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

# 配置浏览器选项
option = webdriver.ChromeOptions()
# 实例化Service对象,指定驱动文件路径
service = Service('./chromedriver.exe')
# 初始化浏览器驱动
driver = webdriver.Chrome(service=service, options=option)

driver.get('https://www.google.com/')

简化方案(可选)

若 ChromeDriver 已添加到系统环境变量中,无需手动指定路径,代码可简化为:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

option = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=option)

driver.get('https://www.google.com/')

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 18:04:54