10

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.

Tyler
  • 509
  • 4
  • 11
  • 23

1 Answers1

12

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")
rentox98
  • 361
  • 1
  • 4
  • 10
  • 2
    This works but it won't firefox won't open if there's already another instance already open, do you know anyway around that? – Tyler Mar 25 '22 at 17:48
  • 1
    I use a profile created only for selenium (https://support.mozilla.org/en-US/kb/profile-manager-create-remove-switch-firefox-profiles), so I can open the instance while an instance of my personal profile of firefox run. If it isn't enough, maybe the possibility of open multiple tabs may help you. – rentox98 Mar 25 '22 at 20:43
  • 2
    It's not a good solution. Selenium normally copies the profile and uses the copy so changes don't affect the next runs. But what you're doing is instruct Firefox to use the profile directly, which makes any changes to it permanent (and affect the next runs). – Niccolo M. Aug 07 '22 at 10:54
  • Yes, I am using this *without specifying a profile* - which is supposed to work, as @NiccoloM. suggested. But, I am still getting the deprecation warnings. – leanne Mar 17 '23 at 20:05