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,210 points
302 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,130 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 in Selenium by anonymous

edited May 2 by Omkar 27 views
0 votes
1 answer
0 votes
1 answer

Headless ChromeDriver using Python Selenium error: Fails To Start— “DevTools request failed”

This should be because your ChromeDriver is ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,030 points
252 views
0 votes
1 answer

Need to perform parallel execution (multiple browser sessions) with Selenium & TestNG by using @BeforeSuite

@Beforesuite annotated method runs before the testNG.XML ...READ MORE

answered Mar 30, 2018 in Selenium by nsv999
• 5,030 points
899 views
0 votes
1 answer

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,030 points
73 views
0 votes
1 answer
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,130 points
446 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
55 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,130 points
445 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,130 points
1,549 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.