无法使用 python 中的 selenium 4 选项.set_preference 加载现有的 firefox 配置文件
我有这段代码可以工作并加载 Firefox 配置文件,
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
ffOptions = Options()
ffProfile = FirefoxProfile(r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
ffOptions.profile = ffProfile
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
只是它给出了以下弃用警告:
firefox_profile已被弃用,请使用Options对象
设置配置文件已被弃用。请使用set_preference 和 install_addons 方法
要解决警告,我尝试将代码更新为
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
ffOptions = Options()
ffOptions.set_preference('profile', r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
现在没有警告,但浏览器打开时未设置配置文件,它是一个空白配置文件。
I have this code that works and loads the firefox profile
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
ffOptions = Options()
ffProfile = FirefoxProfile(r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
ffOptions.profile = ffProfile
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
Only it gives the following deprecation warnings:
firefox_profile has been deprecated, please use an Options object
Setting a profile has been deprecated. Please use the set_preference
and install_addons methods
To resolve the warnings I've tried updating my code to
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
ffOptions = Options()
ffOptions.set_preference('profile', r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
Now there are no warnings but the profile is not set when the browser opens, it's a blank profile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,这对我有用:
I had the same problem and this worked for me: