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

Selenium中executable_path已弃用,新手求助如何改用Service对象?

解决Selenium中executable_path弃用的警告问题

Selenium 4.x版本起,executable_path参数已被弃用,必须通过Service对象来指定浏览器驱动的路径,修改驱动初始化代码即可消除警告。

修改后的完整代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service

# 创建Service实例,传入chromedriver路径
service = Service('./chromedriver')
# 将Service对象传入Chrome构造方法
driver = webdriver.Chrome(service=service)

小提示:如果你的ChromeDriver已经添加到系统环境变量中,无需手动指定路径,直接写service = Service()即可,Selenium会自动查找驱动文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 04:52:02