Selenium, how to start Firefox with addons?

13,667

Solution 1

I don't have enough Stackoverflow rep to leave a comment on your question, and unfortunately I don't know the answer to your question, but for what it's worth you need to call webdriver.Firefox() with firefox_profile, not browser_profile, as you have done.

See also: http://code.google.com/p/selenium/source/browse/trunk/py/selenium/webdriver/firefox/webdriver.py#33

Solution 2

what I did and worked was:

profile=webdriver.FirefoxProfile()
profile.add_extension("/home/.../.mozilla/firefox/zrdb9ki8.default/extensions/{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}.xpi") # for adblockplus

profile.set_preference("extensions.adblockplus.currentVersion", "2.8.2")
Fox = webdriver.Firefox(profile)
Fox.get(website_Url) #https://.....

Solution 3

It took me a few hours to find a solution.

All you need to do is download your extension as .xip file.

And then add this line to your code:

driver.install_addon('/Users/someuser/app/extension.xpi', temporary=True)

Replace "/Users/someuser/app/extension.xpi" with path to your extension .xip file.

Solution 4

Additionally you should not open the xpi file directly. Instead try to just give the address:

firefoxProfile.add_extension(wd + "/requestpolicy.xpi")
Share:
13,667
jgillich
Author by

jgillich

Updated on June 12, 2022

Comments

  • jgillich
    jgillich almost 2 years

    I want to load the Firefox Addon RequestPolicy. This is how i tried it:

    rp = open(wd + "/requestpolicy.xpi")
    firefoxProfile = FirefoxProfile()
    firefoxProfile.add_extension(rp)
    
    self.driver = webdriver.Firefox(firefoxProfile)
    
    self.usr = user.User(self.driver, username, password, world)
    self.usr.login()
    

    No error, according to the Docs it should work, but it doesn't, it still starts without the addon.

    Next thing i've tried is calling it this way:

    self.driver = webdriver.Firefox(browser_profile=firefoxProfile)
    

    Output:

    TypeError: __init__() got an unexpected keyword argument 'browser_profile'
    

    But this is an aspect of python i dont know much about. I got that idea because the source looks that way.

  • Andre
    Andre almost 3 years
    this method does not exist in C# API - Profile.AddExtension does not work either ...
  • Arthur Stepanov
    Arthur Stepanov almost 3 years
    yes, because we are talking about Python :)