85

The Selenium documentation mentions that the Chrome webdriver can take an instance of ChromeOptions, but I can't figure out how to create ChromeOptions.

I'm hoping to pass the --disable-extensions flag to Chrome.

alecxe
  • 441,113
  • 110
  • 1,021
  • 1,148
k107
  • 14,993
  • 7
  • 58
  • 58

4 Answers4

142

Found the chrome Options class in the Selenium source code.

Usage to create a Chrome driver instance:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=chrome_options)
congusbongus
  • 12,079
  • 5
  • 68
  • 93
k107
  • 14,993
  • 7
  • 58
  • 58
  • 7
    This answer was a lifesaver. In case it's useful to others, to enable ES6 Harmony features, the call is `chrome_options.add_argument("--js-flags=--harmony")` – msridhar Jun 18 '14 at 00:04
  • 11
    Note: `chrome_options` arg is now deprecated in favor of the simpler `options`, e.g.: `driver = webdriver.Chrome(options=chrome_options)` – mblakesley Jan 31 '19 at 23:29
  • Hey, @k107 I was wondering If I can do the same thing except for one change. Can I use `chrome_options.add_argument("--enable-extensions")` to enable all **extensions** instead of adding each extension manually by (code)? Thanks in advance! – Youssof H. Sep 08 '19 at 21:00
16

This is how I did it.

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-extensions')

chrome = webdriver.Chrome(chrome_options=chrome_options)
Hassan Raza
  • 2,695
  • 21
  • 32
6

Code which disable chrome extensions for ones, who uses DesiredCapabilities to set browser flags :

desired_capabilities['chromeOptions'] = {
    "args": ["--disable-extensions"],
    "extensions": []
}
webdriver.Chrome(desired_capabilities=desired_capabilities)
Andriy Ivaneyko
  • 18,421
  • 4
  • 52
  • 73
3
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--disable-logging')

# Update your desired_capabilities dict withe extra options.
desired_capabilities.update(options.to_capabilities())
driver = webdriver.Remote(desired_capabilities=options.to_capabilities())

Both the desired_capabilities and options.to_capabilities() are dictionaries. You can use the dict.update() method to add the options to the main set.

user3389572
  • 351
  • 2
  • 5