Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Firefox not adding extensions

Tags:

c#

selenium

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)


1 Answers

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

like image 65
Tomi Avatar answered Feb 05 '26 10:02

Tomi