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

6.8k Views Asked by At

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.

1

There are 1 best solutions below

4
On BEST ANSWER

I had the same problem and this worked for me:

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