5

I am using Selenium web driver to develop an automated test using Chrome as my browser. I am using Python for this.

I have an extension on my Chrome browser that I would like enabled when Selenium opens Chrome. The problem is that when Selenium opens Chrome all the extensions are disabled by default.

How do I enable all or a certain extension on the Chrome browser when Selenium runs?

Kyll
  • 7,036
  • 7
  • 41
  • 64
SkyBlue
  • 293
  • 4
  • 13

1 Answers1

4

You can accomplish this using ChromeOptions class or DesiredCapabilities. For that you have to have the .crx file and load that with driver instance.

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


executable_path = "path_to_webdriver"
os.environ["webdriver.chrome.driver"] = executable_path

chrome_options = Options()
chrome_options.add_extension('path_to_extension')

driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)
driver.get("http://stackoverflow.com")
driver.quit()

Code taken from @alecxe answer here and more details about ChromeOptions and DesiredCapabilities here

Community
  • 1
  • 1
Saifur
  • 16,081
  • 6
  • 49
  • 73