4

I want to Load Zenmate Firefox Addons when selenium webdriver runs it runs fine when i run without loading any addons ( extensions ) but having problem while adding any addons . Here is my Code :

def __init__(self):   

        self.main_catag_driver = []
        self.declare_xpaths()
        self.main_web_url = "Some_website_url"
        self.path_fire_fox_file = "~/.mozilla/firefox/7rl1aw4c.default/extensions/[email protected]"
        self.driver = webdriver.Firefox()
        self.driver.add_extension(extension=self.path_fire_fox_file)
        time.sleep(5)
        self.driver.get(self.main_web_url)

Error when loading Bar :

Traceback (most recent call last):
  File "scrap.py", line 73, in <module>
    obj = carandclassic()
  File "scrap.py", line 28, in __init__
    self.driver.add_extension(extension=self.path_fire_fox_file)
AttributeError: 'WebDriver' object has no attribute 'add_extension'

2 Answers 2

5

add_extension() is a method on FirefoxProfile, not WebDriver:

profile = webdriver.FirefoxProfile()
profile.add_extension(extension=self.path_fire_fox_file)

self.driver = webdriver.Firefox(profile)

Plus, I'm not sure if you really need that time.sleep(5) call - try without wasting 5 seconds.

1
  • Amazing, found this after lots of searching, so UNDERRATED.
    – anantdark
    Oct 15, 2020 at 23:20
1

While I agree with alecxe, it only worked for some of my extensions. I managed to install all of them successfully (from .xpi files) with install_addon() which is called on already instantiated webdriver.Firefox:

driver = webdriver.Firefox(executable_path='path_to_geckodriver')
# Path to .xpi file needs to be an absolute path. I think it must be a string too.
driver.install_addon(str(Path('extensions/some_extension.xpi').absolute()))

driver.get("about:addons")  # One step closer to see all extensions at glance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.