Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install extension permanently in geckodriver

I need to test Firefox using an extension. I want to automate the test and visit several websites.

I installed Selenium and it opens in geckodriver. However, the extension is not there. I can install it manually from about:debugging but the problem is that I want the Selenium test to launch the gecko driver while the extension is already there. How to do this? How to install the extension permanently in the geckodriver so it is there when I launch the geckodriver from selenium?

EDIT: I also tried to install the extension (add it to the browser) from the Firefox extensions websites. It gets added but once I close the gecko window, the extension disappear in the next run. How to install it permanently?

like image 931
user9371654 Avatar asked Oct 25 '25 15:10

user9371654


2 Answers

Note: OP didn't specify a language, so this answer is for Python. The other Selenium WebDriver language bindings have similar mechanisms for creating profiles and adding extensions.


You can install the Extension each time you instantiate the driver.

First, download the extension (XPI file) you want from: https://addons.mozilla.org.

Then, in your code... create a FirefoxProfile() and use the add_extension() method to add the extension. Then you can instantiate a driver using that profile.

For example, this will launch Firefox with a newly created profile containing the "HTTPS Everywhere" extension:

from selenium import webdriver

profile = webdriver.FirefoxProfile() 
profile.add_extension(extension='https_everywhere-2019.1.31-an+fx.xpi')
driver = webdriver.Firefox(firefox_profile=profile) 
like image 131
Corey Goldberg Avatar answered Oct 28 '25 05:10

Corey Goldberg


You need to launch geckdriver with an exisitng profile by specifying the profile path of firefox

For python you can do it by this:

profile = FirefoxProfile('/home/student/.mozilla/firefox/gwi6uqpe.Default') // change this path
browser = webdriver.Firefox(firefox_profile=profile)

For C# you can do this:

string path = @"C:\Users\username\AppData\Local\Mozilla\Firefox\Profiles\myi5go1k.default";
FirefoxProfile ffprofile = new FirefoxProfile(path);
Driver = new FirefoxDriver(ffprofile);
like image 44
Oussail Avatar answered Oct 28 '25 03:10

Oussail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!