Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed
Try to download HERE and use this latest chrome driver version:
- https://sites.google.com/chromium.org/driver/
Try this:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/<user>/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')
chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed error using Selenium through Python
You need to take care of a couple of things as follows:
options.binary_location
: Refers to the google-chrome binary location and is used if Google Chrome isn't installed at the default location. See: WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome--remote-debugging-port
: If you aren't remote debugging, you can drop this argument safely.chrome_driver_binary
: Referes to the absolute location of the ChromeDriver within your system.webdriver.Chrome(chrome_driver_binary, options = options)
: Additionally you may like to add the key executable_path as as follows:chrome_driver_binary = '/home/myname/projects/myproject/chromedriver'
driver = webdriver.Chrome(executable_path=chrome_driver_binary, options = options)
driver.get('http://www.ubuntu.com/')--no-sandbox
,--headless
,--disable-dev-shm-usage
,--disable-setuid-sandbox
, etc are optional settings which you may not require to start off.
The minimum code block to initiate a Selenium driven ChromeDriver initiated google-chrome Browsing Context can be:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(executable_path='/home/myname/projects/myproject/chromedriver', options=options)
driver.get("http://www.ubuntu.com/")
A common cause for Chrome to crash during startup is running Chrome as
root
user (administrator
) on Linux. While it is possible to work around this issue by passing--no-sandbox
flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.
References
You can find a couple of relevant detailed discussions in:
- How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium?
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally using Selenium ChromeDriver and Chrome through WebDriverManager
You need to take care of a couple of things here as follows:
You need
webdriver.Chrome()
only once. If you don't need the arguments throughOptions()
keep:driver = webdriver.Chrome(service=service)
and remove:
driver = webdriver.Chrome(ChromeDriverManager().install(),options=chrome_options)
or vice versa.
If you are executing as a non-root using
add_argument('--headless')
generally you may not even require the following arguments:add_argument('--no-sandbox')
add_argument('--disable-dev-shm-usage')
You can try to initiate the new Browsing Context i.e. google-chrome-headless using:
driver = webdriver.Chrome(service=ChromeDriverManager().install(), options=chrome_options)
Your effective code block will be:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = Options()
chrome_options.add_argument('--headless')
# optional
chrome_options.add_argument('--no-sandbox')
# optional
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(ChromeDriverManager().install(),options=chrome_options)
driver.get('http://192.168.15.1/me_configuracao_avancada.asp')
Note: Ensure that you have installed webdriver-manager and Chrome browser within your system before you kickoff your test execution.
Related Topics
Pandas Groupby With Delimiter Join
Difference Between Map, Applymap and Apply Methods in Pandas
Why Does Substring Slicing With Index Out of Range Work
Catch Multiple Exceptions in One Line (Except Block)
How to Properly Ignore Exceptions
What Causes My Function to Return None At the End
Numpy or Pandas: Keeping Array Type as Integer While Having a Nan Value
How to List All Functions in a Module
How to Calculate Sum of Prime Numbers from List of Integers in Python
How to Install Python Packages [Ssl: Tlsv1_Alert_Protocol_Version]
Binning a Column With Python Pandas
Use a List of Values to Select Rows from a Pandas Dataframe
Converting Between Datetime, Timestamp and Datetime64
Find the Row Indexes of Several Values in a Numpy Array
How to Run a Python Script as a Service in Windows
How to Initialize a Dictionary of Distinct Empty Lists in Python