更新时间:2022-12-08 10:56:04
此错误消息.
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
.表示键executable_path
将在即将发布的版本中弃用。
此更改与Selenium 4.0 Beta 1changelog一致,其中提到:
不推荐使用驱动程序实例化中除Options
和Service
参数之外的所有参数。(#9125,#9128)
解决方案
使用selenium4作为键
executable_path
已弃用,您必须将Service()
类的实例与ChromeDriverManager().install()
命令一起使用,如下所述。前提条件
确保:
Selenium升级到v4.0.0
pip3 install -U selenium
Python的WebDriver Manager已安装
pip3 install webdriver_manager
中找到有关安装WebDriver Manager for Python的详细讨论Selenium v4兼容代码挡路
from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) driver.get("https://www.google.com")
控制台输出:
[WDM] - ====== WebDriver manager ====== [WDM] - Current google-chrome version is 96.0.4664 [WDM] - Get LATEST driver version for 96.0.4664 [WDM] - Driver [C:UsersAdmin.wdmdriverschromedriverwin3296.0.4664.45chromedriver.exe] found in cache
您可以在Selenium ChromeDriver issue using Webdriver Manager for Python
中找到有关安装WebDriver Manager for Python的详细讨论
如果要传递
Options()
对象,可以使用:from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager options = Options() options.add_argument("start-maximized") driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) driver.get("https://www.google.com")
TL;DR
您可以在以下地址找到相关的Bug报告/拉取请求: