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


We can pass options to the Selenium Chrome driver using Python. This can be with the help of the ChromeOptions and the DesiredCapabilities class. For the ChromeOptions, we have to create an object for that class.

Then we shall take the help of the add_argument method and pass the option we want to send to the browser as a parameter to the method. Finally, this information must be given to the web driver.

Example

Code Implementation.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
#object of ChromeOptions
op = webdriver.ChromeOptions()
#add option
op.add_argument('--enable-extensions')
#pass option to webdriver object
driver = webdriver.Chrome(chrome_options=op)

We can also add capabilities with the help of DesiredCapabilities class.

Code Implementation.

#object of DesiredCapabilities
c = webdriver.DesiredCapabilities.Chrome.copy()

#set capability to True
c['acceptInsecureCerts'] = True
#pass capability to webdriver object
driver = webdriver.Chrome(desired_capabilities=c)

In this way, we can pass the Chrome options.

Updated on: 28-Dec-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements