pythonselenium-webdriverfirefoxselenium-firefoxdriver

Load firefox default profile in selenium 4.18.1 python


I am trying to load My default profile of firefox but cant load it I have tried all kinds of approach but nothing is working please help.

The approaches i have tried please anyone help with this

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

options = Options()
options.set_profile('/path/to/default/profile')

driver = webdriver.Firefox(options=options)

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

options = Options()
options.profile = '/path/to/default/profile'

driver = webdriver.Firefox(options=options)

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


ffOptions = webdriver.FirefoxOptions()

ffOptions.add_argument("-profile")
ffOptions.add_argument(f"{os.getenv('LOCALAPPDATA')}\\Mozilla\\Firefox\\Profiles\\a9uwbprg.default-release-1708619541786")
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import os


ffOptions = webdriver.FirefoxOptions()

ffOptions.profile= webdriver.FirefoxProfile(f"{os.getenv('LOCALAPPDATA')}\\Mozilla\\Firefox\\Profiles\\a9uwbprg.default-release-1708619541786")
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options

pf = f"{os.getenv('LOCALAPPDATA')}\\Mozilla\\Firefox\\Profiles\\a9uwbprg.default-release-1708619541786"
options=Options()
options.set_preference('profile', pf)
driver = webdriver.Firefox(options=options)

driver.get("https:google.com")


Solution

  • I think you are almost there, but you are using LOCALAPPDATA not APPDATA.

    Thus the profile path string should be:

    f"{os.getenv('APPDATA')}\\Roaming"
    + "\\Mozilla\\Firefox\\Profiles\\a9uwbprg.default-release-1708619541786"
    

    In summary of your snippets:

    1. There is no Options().set_profile as far as I am aware.
    2. Should work if the correct path is used.
    3. Should also work if the correct path is used.
    4. Same as 2, 3, and 4.
    5. Not sure if this is still supported. The other methods are more direct.

    Bonus one additional way to load a profile.