Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass options to the Selenium Chrome driver using Python?

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.

like image 893
k107 Avatar asked Oct 02 '12 21:10

k107


People also ask

How do I change Chrome options in Selenium?

Create an object of DesiredCapabilities Chrome class and merge the Desired Capabilities class object with Chrome Options class object using merge method. Create an object of Chrome Driver class and pass the Chrome Options Selenium object as an argument.


2 Answers

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) 
like image 161
k107 Avatar answered Sep 30 '22 07:09

k107


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) 
like image 33
Hassan Raza Avatar answered Sep 30 '22 06:09

Hassan Raza