Can't run Chromedriver in headless mode using Selenium


running my selenium script I ran into an error that I don’t know how to pass. I’ve googled and tried various solutions but they didn’t work.
Here is my code:

from selenium import webdriver
from import Options

chrome_driver_binary = '/home/user/Projects/myproject/chromedriver'
options = Options()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(executable_path=chrome_driver_binary, options = options)

And everytime I run this I get the error "The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed."

However, if I comment out the line "options.add_argument("–headless")" my code works perfectly fine. But I can’t leave that commented out because I need that script to run in headless mode.

I am using Ubuntu 22.04 on VirtualBox 7, Python 3.10.6 and run my code in virtual environment.

Asked By: syrok



You can use the newer headless mode (for Chrome 109 and newer):


If you have an older version of Chrome, the syntax will be different. (See the link for details.)

Answered By: Michael Mintz