I am getting this error when I run my tests with selenium using chromedriver.
selenium.common.exceptions.WebDriverException: Message: u'unknown error: Chrome failed to start: exited abnormally\n (Driver info: chromedriver=2.9.248316,platform=Linux 3.8.0-29-generic x86)'
I did download google-chrome stable and also chromedriver and have used this code to start the browser.
driver = webdriver.Chrome('/usr/local/bin/chromedriver')
Any suggestions anyone? Thanks.
For Linux :
Start the Display before start the Chrome. for more info click here
from pyvirtualdisplay import Display display = Display(visible=0, size=(800, 800)) display.start() driver = webdriver.Chrome()
To help debug this problem you can use the service_log_path
and service_args
arguments to the selenium webdriver to see output from the chromedriver:
service_log_path = "{}/chromedriver.log".format(outputdir) service_args = ['--verbose'] driver = webdriver.Chrome('/path/to/chromedriver', service_args=service_args, service_log_path=service_log_path)
I was getting this same exception message and found two ways to get past it; I'm not sure if the OP's problem is the same, but if not, the chromedriver log will hopefully help. Looking at my log, I discovered that the chromedriver (I tried 2.9 down to 2.6 while trying to fix this problem) decides which browser to run in a very unexpected way. In the directory where my chromedriver is located I have these files:
$ ls -l /path/to/ -rwx------ 1 pjh grad_cs 5503600 Feb 3 00:07 chromedriver-2.9 drwxr-xr-x 3 pjh grad_cs 4096 Mar 28 15:51 chromium
When I invoke the chromedriver using the same python code as the OP:
driver = webdriver.Chrome('/path/to/chromedriver-2.9')
This leads to the exception message. In the chromedriver.log I found this message:
[1.043][INFO]: Launching chrome: /path/to/chromium ...
Unbelievable! The chromedriver is trying to use /path/to/chromium
(which is not an executable file, but a directory containing source code) as the browser to execute! Apparently chromedriver tries to search the current directory for a browser to run before searching my PATH
. So, one easy solution to this problem is to check the directory where the chromedriver
is located for files/directories like chrome
and chromium
and move them to a different directory than the chromedriver
.
A better solution is to explicitly tell selenium / chromedriver which browser to execute by using the chrome_options argument:
options = webdriver.ChromeOptions() options.binary_location = '/opt/google/chrome/google-chrome' service_log_path = "{}/chromedriver.log".format(outputdir) service_args = ['--verbose'] driver = webdriver.Chrome('/path/to/chromedriver', chrome_options=options, service_args=service_args, service_log_path=service_log_path)
The chromedriver.log now shows:
[0.999][INFO]: Launching chrome: /opt/google/chrome/google-chrome ...
as expected.
If using Linux make sure you are not running as root. That what gave me the error.
I was faced with the same issue and fixed it by installing Chrome in:
C:\Users\..\AppData\Local\Google\Chrome\Application
You can do this by running the Chrome Setup and saying no when prompted by the User Account Control.