DeprecationWarning: executable_path has been deprecated, please pass in a Service object [英] DeprecationWarning: executable_path has been deprecated, please pass in a Service object
问题描述
我今天开始了一个 selenium 教程,在尝试运行代码时遇到了这个错误.我尝试了其他方法,但最终得到了同样的错误.我在使用 VSC 的 MacOS 上.
I started a selenium tutorial today and have run into this error when trying to run the code. I've tried other methods but ultimately get the same error. I'm on MacOS using VSC.
我的代码:
from selenium import webdriver
PATH = '/Users/blutch/Documents/Chrom Web Driverchromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.get("https://www.google.com")
我也尝试在/Users 前面插入 C:.谁能指导我为什么会发生这种情况/如何解决它?
I've also tried inserting C: in front of /Users. Can anyone guide me on why this is happening/how to fix it?
推荐答案
这个错误信息...
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
...暗示 key executable_path
将在即将发布的版本中弃用.
...implies that the key executable_path
will be deprecated in the upcoming releases.
此更改与 Selenium 4.0 Beta 1 changelog 其中提到:
This change is inline with the Selenium 4.0 Beta 1 changelog which mentions:
在驱动程序实例化中弃用除 Options
和 Service
参数之外的所有参数.(#9125,#9128)
Deprecate all but
Options
andService
arguments in driver instantiation. (#9125,#9128)
解决方案
一旦 key executable_path
被弃用,您必须使用 Service()
类的实例作为如下:
Solution
Once the key executable_path
is deprecated you have to use an instance of the Service()
class as follows:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s = Service('C:/Users/.../chromedriver.exe')
driver = webdriver.Chrome(service=s)
TL;博士
您可以在以下位置找到一些相关的详细讨论:
TL; DR
You can find a couple of relevant detailed discussion in:
- 错误报告:在驱动程序实例化中弃用除选项和服务参数以外的所有参数李>
- 拉取请求:在驱动程序实例化中弃用除选项和服务参数以外的所有参数李>
这篇关于DeprecationWarning: executable_path has been deprecated, please pass in a Service object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!