I am using the same code that's in the recent patch notes and it's still not working.
options = ChromeOptions()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
My code works without headless mode, otherwise, I get this error:
raise TimeoutException(message, screen, stacktrace)
I also tried this and it didn't work:
service = Service(executable_path=r"C:\Program Files (x86)\WebDrivers\chromedriver.exe")
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(service=service, options=options)
selenium 4.18.0 Python 3.10.7
The cumbersome settings of Selenium and its web drivers is one of the reasons why I created Browserist as an extension to Selenium. Headless mode simply works out of the box with Browserist.
In full disclosure, I'm the author of this package. Browserist is lightweight, less verbose extension of the Selenium web driver that makes browser automation even easier. Simply install the package with
pip install browseristand you're ready to go.Maybe something like this could solve your problem?
Browserist has a mature set of methods to interact with web pages, but if you prefer working with the Selenium web driver, you can also return to the standard
driverand continue your script with this:Note that simple settings of headless mode of Browserist work across browser types, so you can even do something like this if you already have Chrome, Edge, Firefox installed: