我正尝试在 MacOS 上通过 PyCharm CE 运行 Selenium,并尝试使用 Google Chrome 运行它。
但是,每当我运行以下命令时:
from selenium import webdriver
browser = webdriver.Chrome("/Users/louiscage/PycharmProjects/SeleniumPractice/chromedriver")
browser.get('https://inventwithpython.com')
这是结果:
/Users/louiscage/PycharmProjects/SeleniumPractice/SeleniumPractice.py:3: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
browser = webdriver.Chrome("/Users/louiscage/PycharmProjects/SeleniumPractice/chromedriver")
我已经下载了适用于 Mac64 的 Chromedriver 和 Geckodriver,并将其放置在我的 PyCharm 项目的正确目录中。但我似乎仍然无法找到解决这个问题的方法。任何帮助将不胜感激。
最佳答案
正如警告所说:请传入一个服务对象
,所以你应该这样做:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service("/Users/louiscage/PycharmProjects/SeleniumPractice/chromedriver")
browser = webdriver.Chrome(service=service)
browser.get('https://inventwithpython.com')
在 chrome Service
类上传递可执行路径,并将其放在变量服务上。然后将其传递给 webdriver chrome。
链接引用在这里:Selenium Chrome webdriver service
https://stackoverflow.com/questions/61862123/
相关文章:
python - matplotlib 为单个散点图添加具有多个条目的图例
amazon-web-services - CognitoIdentityCredentials 不
react-native - React 导航 5(导航到另一个堆栈屏幕)
forms - 如何判断表单字段在 vue.js 中是否无效
python - 在对数刻度上生成均匀间隔的值(如 `np.linspace()` ,但在对数刻度上
amazon-web-services - 有没有办法使用 aws cloudformation 更