How do I pass Chromeoptions in Selenium using Python?
Hey MiroslavRalevic,
To use ChromeOptions in Selenium using Python you can use the ‘add_argument’ methods
from selenium import webdriver
options = webdriver.ChromeOptions() options.add_argument(‘–headless’) # Example option
driver = webdriver.Chrome(options=options)
MiroslavRalevic,
Agree, but you can also use add_experimental_option method to use Chromeoptions in Selenium using Python.
example: from selenium import webdriver
options = webdriver.ChromeOptions() options.add_experimental_option(‘excludeSwitches’, [‘enable-logging’])
driver = webdriver.Chrome(options=options) driver.get(‘https://www.example.com’)
print(driver.title) driver.quit()
Hello MiroslavRalevic,
When I want to use the Chromeoptions method, I prefer using the add_extension method.
from selenium import webdriver
options = webdriver.ChromeOptions() options.add_extension(‘/path/to/extension.crx’) # Example extension
driver = webdriver.Chrome(options=options) driver.get(‘https://www.example.com’)
print(driver.title) driver.quit()