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

解决warning:DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Edge('C:/Users/cong/AppData/Local/Programs/Python/Python310/msedgedriver.exe',options=option)

这个警告信息是在使用Python的Selenium库时出现的。它提示说“executable_path”已经被弃用了,建议使用一个Service对象来传递驱动程序路径。

解决这个问题的方法是使用webdriver.Edge的构造函数来创建一个Service对象,然后将其传递给webdriver.EdgeOptions的service属性。以下是示例代码:

from selenium import webdriver
from selenium.webdriver.edge.service import Service

# 创建一个Service对象
service = Service('C:/Users/cong/AppData/Local/Programs/Python/Python310/msedgedriver.exe')

# 创建一个EdgeOptions对象,并设置一些选项
options = webdriver.EdgeOptions()
options.add_argument('--start-maximized')

# 将Service对象传递给EdgeOptions的service属性
options.service = service

# 创建一个Edge浏览器的WebDriver实例
driver = webdriver.Edge(options=options)

# 访问网页
driver.get('https://www.google.com')

这样就不会出现“DeprecationWarning: executable_path has been deprecated, please pass in a Service object”的警告信息了。

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2023年7月6日
下一篇 2023年7月6日

相关推荐