Selenium 仅以已弃用的方式加载配置文件 (Python)
我尝试了推荐的加载配置文件的方法,但它对我不起作用。它只是打开一个空的配置文件。
from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
profile_path = r'E:/Python/seleniumProfile'
options=Options()
options.set_preference('profile', profile_path)
driver = Firefox(options=options)
driver.get("https://www.google.com")
即使我输入无效的文件夹作为 profile_path,也不会给出警告或错误消息。
旧方法效果很好,但会给出弃用警告:
fp = webdriver.FirefoxProfile('E:/Python/seleniumProfile')
driver = webdriver.Firefox(fp)
driver.get("https://www.google.com")
DeprecationWarning:firefox_profile 已被弃用,请使用选项对象
我想我可以忍受这些警告,但任何帮助将不胜感激。
I tried the recommended method of loading a profile, but it's not working for me. It simply opens an empty profile.
from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
profile_path = r'E:/Python/seleniumProfile'
options=Options()
options.set_preference('profile', profile_path)
driver = Firefox(options=options)
driver.get("https://www.google.com")
No warning or error message is given, even if I type an invalid folder as the profile_path.
Old way works great, but gives the deprecation warning:
fp = webdriver.FirefoxProfile('E:/Python/seleniumProfile')
driver = webdriver.Firefox(fp)
driver.get("https://www.google.com")
DeprecationWarning: firefox_profile has been deprecated, please use an Options object
I guess I can live with the warnings, but any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此错误消息...
...意味着
FirefoxProfile()
的使用已弃用,并且 selenium4 并使用自定义配置文件,您必须使用选项
的实例。此弃用警告与以下变更日志一致:Selenium 4 beta 1
Options
和Service
参数之外的所有参数。 (#9125,#9128)硒4β 2
Selenium 4 Beta 3
解决方案
要使用现有的 firefox 配置文件,您可以使用以下解决方案:
tl; dr
设置自定义配置文件
This error message...
...implies that usage of
FirefoxProfile()
have been Deprecated and with selenium4 and to use a custom profile you have to use an instance ofOptions
. This DeprecationWarning was inline with the following CHANGELOGS:Selenium 4 beta 1
Options
andService
arguments in driver instantiation. (#9125,#9128)Selenium 4 beta 2
Selenium 4 Beta 3
Solution
To use an existing firefox profile you can use the following solution:
tl; dr
Setting a custom profile