Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

selenium - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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) 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...