Search code examples
pythonseleniumfirefoxautomation

How to setup firefox profile in selenium correctly?


I have the following code for selenium in python to use my firefox profile, the idea is to save me from login into my frequently visited pages every time, but Selenium still start itself with no 'memory' or 'history' of me being log in to those pages and stayed login.

What goes wrong please?

def create_selenium_FF():
    options = Options()
    profile = webdriver.FirefoxProfile('/Users/Victor 1/Library/Application Support/Firefox/Profiles/z3ay0enb.default')
    driver = webdriver.Firefox(profile)
    driver = webdriver.Firefox()
    return driver

Solution

  • Normally this would do

    from selenium import webdriver
    from selenium.webdriver.firefox.webdriver import FirefoxProfile
    
    profile = FirefoxProfile("C:\\Path\\to\\profile")
    driver = webdriver.Firefox(profile)
    

    As some of the options, such as firefox_profile and options.profile are mutually exclusive, precedence is given from how specific the setting is. capabilities is the least specific keyword argument, followed by options, followed by firefox_binary and firefox_profile.

    In practice this means that if firefox_profile and options.profile are both set, the selected profile instance will always come from the most specific variable. In this case that would be firefox_profile. This will result in options.profile to be ignored because it is considered a less specific setting than the top-level firefox_profile keyword argument. Similarily, if you had specified a capabilities[“moz:firefoxOptions”][“profile”] Base64 string, this would rank below options.profile.

    Can't see your entire code but looks like you have your answer in the above

    Read it all here:- https://selenium-python.readthedocs.io/api.html?highlight=profile#module-selenium.webdriver.firefox.webdriver