How to load firefox profile with Python Selenium?

前端 未结 5 975
囚心锁ツ
囚心锁ツ 2021-02-14 20:19

I\'m trying to get Python Selenium to work on my Windows Machine. I\'ve upgraded to the latest versions of Firefox, Selenium, Geckodriver, but I still receive the below error: <

5条回答
  •  遥遥无期
    2021-02-14 20:46

    Solution:

    from selenium import webdriver
    fp = webdriver.FirefoxProfile('/home/gabriel/.mozilla/firefox/whatever.selenium')
    driver = webdriver.Firefox(fp)
    

    I struggled until I found this issue which is now solved but was helpful because it shows some commands.

    first version, not working because I could not connect with selenium afterward:

    from selenium.webdriver.firefox.options import Options
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    options = Options()
    options.add_argument("-profile")
    options.add_argument("/home/gabriel/.mozilla/firefox/whatever.selenium")
    firefox_capabilities = DesiredCapabilities.FIREFOX
    firefox_capabilities['marionette'] = True
    driver = webdriver.Firefox(capabilities=firefox_capabilities, firefox_options=options)
    

    I am sure that this loads the profile "whatever.selenium" because if I go to about:profiles I can read:

    Profile: selenium This is the profile in use and it cannot be deleted.

    Even though "whatever.selenium" is not the default profile on my system.

    Remark: at least one the profile parameters is overridden by selenium (or geckodriver?): Preferences > Privacy and Security > "Block pop-up windows" is always reseted to off. So use about:profiles to make assertions on which profile you are running.

    notes:

    • firefox_capabilities might not be needed in above code.
    • tested under Firefox 60.4.0esr (64-bit), geckodriver 0.23.0 ( 2018-10-04), selenium 3.141.0 with Python 3.5.3

提交回复
热议问题