无法使用 python 中的 selenium 4 option.set_preference 加载现有的 firefox 配置文件

Unable to load existing firefox profile with selenium 4's option.set_preference in python

我有这段代码可以工作并加载 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\Profiles53x1pz.default')
ffOptions.profile = ffProfile

driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")

只有它给出以下弃用警告:

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

为了解决警告,我尝试将我的代码更新为

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\Profiles53x1pz.default')
    
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")

现在没有警告,但打开浏览器时未设置配置文件,它是空白配置文件。

我遇到了同样的问题,这对我有用:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options


ffOptions = Options()

ffOptions.add_argument("-profile")
ffOptions.add_argument(r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles53x1pz.default')
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")