Selenium Firefox not adding extensions

Viewed 1543

I'm trying to get ublock installed on Firefox with Selenium. The problem is, the extension won't load. The browser loads fine but does not add the extension.

FirefoxProfile profile = new FirefoxProfile();
profile.AddExtension("ublock_origin-1.17.4-an+fx.xpi");
FirefoxOptions options = new FirefoxOptions
{
    Profile = profile
};
IWebDriver driver = new FirefoxDriver(options);

I've seen this but I don't want to use an old version of firefox, and i haven't seen any other fix for it.

Currently using v0.23.0 of geckodriver for win64.

How can I add extensions to firefox with selenium? (without using an old version)

2 Answers

Try splitting out the options part, see if that makes a difference:

FirefoxProfile profile = new FirefoxProfile();
profile.AddExtension(*file path*);
FirefoxOptions options = new FirefoxOptions();
options.Profile = profile;
IWebDriver driver = new FirefoxDriver(options);
FirefoxProfile profile = new FirefoxProfile();
FirefoxOptions options = new FirefoxOptions
{
    Profile = profile
};
IWebDriver driver = new FirefoxDriver(options);
firefoxDriver.InstallAddOnFromFile("ublock_origin-1.17.4-an+fx.xpi"); // Dear Wizard, this is the magic

Use Selenium 4.X and use the FirefoxDriver.InstallAddOnFromFile method instead of the the FirefoxOptions.AddExtension

Related