Home > database >  chrome in headless mode with selenium
chrome in headless mode with selenium

Time:09-24

How to open chrome in headless mode with selenium? I tried

chromeOptions = Options()
chromeOptions.add_argument("headless")
self.driver = webdriver.Chrome(ChromeDriverManager().install(), options=chromeOptions)

but this just returns an error:

Error with Permissions-Policy header: Unrecognized feature: 'interest-cohort'.", source: (0)

CodePudding user response:

This is wrong way

chromeOptions.add_argument("headless")

try this

chromeOptions.add_argument("--headless")

I am using these config in my project, so thought it would be helpful to you.

options = webdriver.ChromeOptions()
options.add_argument("--disable-infobars")
options.add_argument("--start-maximized")
options.add_argument("--disable-extensions")
options.add_argument('--window-size=1920,1080')
options.add_argument("--headless")
driver = webdriver.Chrome(executable_path = driver_path, options = options)

Note that driver_path is basically the chromedriver.exe, if ChromeDriverManager().install() works for you better stick with that.

CodePudding user response:

headless is not a correct command format. Chrome command line switch always starts with -- that means it should be --headless

--headless: Run in headless mode, i.e., without a UI or display server dependencies.

Code:

chromeOptions = Options()
chromeOptions.add_argument("--headless")
self.driver = webdriver.Chrome(ChromeDriverManager().install(), options=chromeOptions)

Please refer the below page for all command line switches and their details,

Reference: https://peter.sh/experiments/chromium-command-line-switches/

  • Related