Selenium: Selenium Python - Passing `firefox_profile` arg doesn't seem to take effect

Created on 11 Oct 2019  路  6Comments  路  Source: SeleniumHQ/selenium

  • selenium==3.141.0 Python package.
  • Firefox version 69.0.3 (64bits)
  • geckodriver 0.25.0

I am trying to launch launch a Firefox browser with an extension installed. I am using the following code:

from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.add_extension("/path/to/extension.xpi")
driver = webdriver.Firefox(firefox_profile=profile)

Now, the Firefox window that pops up doesn not have the extension installed. When I look in "about:support", I can see that the "Profile folder" is different than the one I can see in Python with driver.profile.path. In fact, checking the geckodriver.log I can see (not full log output for readability):

INFO    Running command: "firefox-bin" "-marionette" "-foreground" "-no-remote" "-profile" "/path/to/profile-A"
WARN    addMetadata: Add-on id-of-my-extension is invalid: Error: File /path/to/profile-A/extensions/id-of-my-extension does not contain a valid manifest(resource://gre/modules/addons/XPIInstall.jsm:671:11) JS Stack trace: [email protected]:671:11
[...]

As you can see, the Firefox command has a -profile argument, but "/path/to/profile-A" is not the path to the profile I created with Python (let's call it /path/to/profile-B). Nevertheless it does try to load the extension from "profile-A", but the thing is that the extension is not present in that path but in the path to "profile-B".

C-py

Most helpful comment

It worked for me with latest stable uBlock xpi.

All 6 comments

I tried that as well and it didn't work.

Checking the docstring in the WebDriver class, I can see that firefox_options is noted as deprecated, but firefox_profile is not. Anyway, I check the code and:

        if options is not None:
            [...]
            if options.profile is not None:
                self.profile = options.profile

       [...]

        if firefox_profile is not None:
            if isinstance(firefox_profile, basestring):
                firefox_profile = FirefoxProfile(firefox_profile)
            self.profile = firefox_profile
            options.profile = firefox_profile

so it would seem that both arguments should have the same effect.

I can reproduce this. As a workaround, it's currently possible to install add-ons using driver.install_addon.

I don't have my computer with me right now, but I have tried to use that method too and I got an exception. The extension I want to install is an .xpi file. Would that work with install_addon()?

It worked for me with latest stable uBlock xpi.

Ok, I'll check as soon as I can and I'll let you know. Thanks!

@DCNick3, thanks!! I have tried with install_addon() and I managed to install the extension. I had a bunch of problems at the begining. First it was complaining because "the file was corrupted", and then it complained about the signature. But finally it has installed it successfully.

This is a valid workaround for my use case, but the reported bug still exists.

Was this page helpful?
0 / 5 - 0 ratings