Error unable to add browser extension to Firefox profile using Selenium

0 votes

I want to use selenium to scrape off some website. I can't access the website via my own internet connection, so I need to use browsec Mozilla add-on for that. I am unable to launch Firefox with selenium with the add-on enabled.

Below are the steps I did:

import selenium

from selenium import webdriver


url = "http://url"

profile = webdriver.FirefoxProfile()

profile.add_extension('browsec@browsec.com.xpi')

#profile.add_extension("C:\Users\urs\AppData\Roaming\Mozilla\Firefox\Profiles\abc.default\extensions\browsec@browsec.com.xpi")

driver = webdriver.Firefox(firefox_profile=profile)


if __name__ == "__main__":

   driver.get(url)

   driver.wait(5)

   driver.quit()

I added the extension in the same directory where my script is kept using the following

profile.add_extension('browsec@browsec.com.xpi')

It through me an error:

Traceback (most recent call last): File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 346, in _addon_details with open(os.path.join(addon_path, 'install.rdf'), 'r') as f: FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Usr\AppD ata\Local\Temp\tmp0hny31u3.browsec@browsec.com.xpi\install.rdf'

During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "test.py", line 7, in profile.add_extension("browsec@browsec.com.xpi") File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 95, in add_extension self._install_extension(extension) File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 274, in _install_extension addon_details = self._addon_details(addon) File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 351, in _addon_details raise AddonFormatError(str(e), sys.exc_info()[2]) selenium.webdriver.firefox.firefox_profile.AddonFormatError: ("[Errno 2] No such file or directory: 'C:\\Users\\Usr\\AppData\\Local\\Temp\\tmp0hn y31u3.browsec@browsec.com.xpi\\install.rdf'", )

I also tried giving the path to the extension:

profile.add_extension("C:\Users\urs\AppData\Roaming\Mozilla\Firefox\Profiles\abc.default\extensions\browsec@browsec.com.xpi")

And I ran into this error:

profile.add_extension("C:\Users\Hassan\AppData\Roaming\Mozilla\Firefox\Profi les\n5jwlj9l.default\extensions\browsec@browsec.com.xpi") ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in positio n 2-3: truncated \UXXXXXXXX escape

Formatting the path string like below doesn't help either.

profile.add_extension(r"C:\Users\urs\AppData\Roaming\Mozilla\Firefox\Profiles\abc.default\extensions\browsec@browsec.com.xpi")

I get the following:

Traceback (most recent call last): File "test.py", line 7, in profile.add_extension(r"C:\Users\Hassan\AppData\Roaming\Mozilla\Firefox\Prof iles\n5jwlj9l.default\extensions\browsec@browsec.com.xpi") File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 95, in add_extension self._install_extension(extension) File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 274, in _install_extension addon_details = self._addon_details(addon) File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\firefox_profile .py", line 351, in _addon_details raise AddonFormatError(str(e), sys.exc_info()[2]) selenium.webdriver.firefox.firefox_profile.AddonFormatError: ("[Errno 2] No such file or directory: 'C:\\Users\\usr\\AppData\\Local\\Temp\\tmp1he 0fym_.browsec@browsec.com.xpi\\install.rdf'", )

How do I configure selenium to run firefox with browsec enabled by default?

Jul 11, 2018 in Selenium by Martin
• 4,320 points
3,163 views

1 answer to this question.

0 votes

Try to create profile on Firefox browser

On windows Run --> type

"firefox.exe -P" ​ 

Create ur new profile. Open the firefox using that profile.

answered Jul 11, 2018 by Samarpit
• 5,910 points

Related Questions In Selenium

0 votes
0 answers

Unable to pass url in firefox and chrome by using selenium webdriver

Hi All, I am not able to run ...READ MORE

May 1, 2019 in Selenium by anonymous

edited May 2, 2019 by Omkar 1,609 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to start Firefox browser on Mac using Selenium Webdriver?

Hey Tom, you can use following commands ...READ MORE

answered Jul 18, 2019 in Selenium by Abha
• 28,140 points
1,657 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,649 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,131 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,209 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,865 views
0 votes
1 answer

Unable to Start tor using Python Selenium Error: failed to start

I tried to solve same problem on ...READ MORE

answered Jun 29, 2018 in Selenium by Samarpit
• 5,910 points
3,773 views
0 votes
1 answer

Firefox browser not opening with given URL using Selenium Webdriver with Java

Download the latest selenium jar and replace ...READ MORE

answered Apr 30, 2018 in Selenium by Samarpit
• 5,910 points
7,774 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP