Categories
Python Answers

How to fix WebDriverException:Chrome failed to start: crashed error with Python Selenium?

Spread the love

Sometimes, we want to fix WebDriverException:Chrome failed to start: crashed error with Python Selenium

In this article, we’ll look at how to fix WebDriverException:Chrome failed to start: crashed error with Python Selenium.

How to fix WebDriverException:Chrome failed to start: crashed error with Python Selenium?

To fix WebDriverException:Chrome failed to start: crashed error with Python Selenium, we set the location of the Chrome binary.

For instance, we write

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = "C:\\path\\to\\chrome.exe"   
options.add_argument("--start-maximized")
options.add_argument("--no-sandbox") 
options.add_argument("--disable-dev-shm-usage")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://example.com/')

to set options.binary to the path of the Chrome binary.

We start Chrome maximized with

options.add_argument("--start-maximized")

And then we disable Chrome sandbox with

options.add_argument("--no-sandbox") 

We stop Selenium from being detected with

options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)

Then we create specify the Chrome path again when we create the driver

driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *