Selenium fails to start Chromedriver

2019-03-26 18:20发布

I am unable to start Chromedriver with Selenium.

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://www.google.com')

It never gets to browser.get('http://www.google.com') but fails with:

    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 3.13.0-76-generic x86_64)

I am on Ubuntu 14.04 (64b) using Python 2.7.6 (virtualenv installation) and selenium==2.50.1.

dm@Z580:~$ which chromedriver
/usr/local/bin/chromedriver

dm@Z580:~$ ll /usr/local/bin/chromedriver
lrwxrwxrwx 1 root root 24 feb  4 22:13 /usr/local/bin/chromedriver -> /opt/google/chromedriver*

EDIT

dm@Z580:~$ google-chrome --version
Google Chrome 48.0.2564.97 

Downgraded to Chromedriver 2.20:

wget http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod 777 chromedriver
sudo mv -f chromedriver /opt/google/chromedriver

but, sadly, still the same result.

Any idea why is this happening?

2条回答
Evening l夕情丶
2楼-- · 2019-03-26 18:41

I don't know if this is the only issue you're having but chromedriver doesn't like "www.google.com", however it is fine with "http://www.google.com"

查看更多
霸刀☆藐视天下
3楼-- · 2019-03-26 18:42

Ok, so the solution is a bit weird.

I moved the Chromedriver binary from /opt/google/ (where Google Chrome is installed itself) to /opt/, updated the symlink and it's working now!

Compared to the question itself, these two lines of code solve the issue:

sudo mv /opt/google/chromedriver /opt/
sudo ln -fs /opt/chromedriver /usr/local/bin/chromedriver

And now I am able to run the following Python code:

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://www.google.com')

Chrome starts and everything.

The following line on the old Selenium docs page inspired me to check and eventually to change the Chromedriver location:

For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.

查看更多
登录 后发表回答