问题描述
我无法使用 Selenium
启动 Chromedriver
.
I am unable to start Chromedriver
with Selenium
.
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://www.google.com')
它永远不会到达 browser.get('http://www.google.com')
但失败了:
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)
我在 Ubuntu 14.04
(64b) 上使用 Python 2.7.6
(virtualenv 安装)和 selenium==2.50.1
.
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*
编辑
dm@Z580:~$ google-chrome --version
Google Chrome 48.0.2564.97
降级到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.
知道为什么会这样吗?
推荐答案
好的,所以解决方案有点奇怪.
我将 Chromedriver
二进制文件从 /opt/google/
(Google Chrome
本身安装)移动到 /opt/
,更新了符号链接,现在可以使用了!
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
现在我可以运行以下 Python 代码:
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 启动,一切正常.
Chrome starts and everything.
旧的 Selenium 文档页面上的以下行启发我去检查并最终更改 Chromedriver
位置:
The following line on the old Selenium docs page inspired me to check and eventually to change the Chromedriver
location:
对于 Linux 系统,ChromeDriver 期望/usr/bin/google-chrome成为实际 Chrome 二进制文件的符号链接.
这篇关于Selenium 无法启动 Chromedriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!