Selenium executable_path 已被弃用

Selenium executable_path has been deprecated

当 运行 我的代码出现以下错误字符串时,

<string>:36: DeprecationWarning: executable_path has been deprecated, please pass in a Service object

可能是什么问题?下面是 Selenium 设置,

options = webdriver.ChromeOptions()
prefs = {"download.default_directory" : wd}
options.add_experimental_option("prefs", prefs)
options.add_argument("--headless")
path = (chrome)
driver = webdriver.Chrome(executable_path=path, options = options)
driver.get('https://www.1linelogin.williams.com/1Line/xhtml/login.jsf?BUID=80')

这个错误信息

DeprecationWarning: executable_path has been deprecated, please pass in a Service object

意味着 key executable_path 将在即将发布的版本中弃用。

一旦 key executable_path 被弃用,您必须使用 Service() class如下:

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

path = (chrome)
s = Service(path)
driver = webdriver.Chrome(service=s)

有关详细信息,请参阅