Env: chromedriver 2.9, google-chrome-stable 34, python 2.6, CentOS6.4 final x86_64
Env: chromedriver 2.9, google- chromestable 34, python 2.6, CentOS6.4 final x86_64
I install google-chrome-stable(not chromium) follow install-chrome.sh. It may extract packages from fedoraproject and install those package to /opt/google/chrome/lib
. I install chromedriver2.9 follow link. I can run google-chrome and chromedriver manually without error. I install selenium by pip install selenium
(selenium 2.41 ). Selenium is installed to /usr/lib/python2.6/site-packages/
. Google-chrome installed at this manner seems not allowed to open as root.
我安装google-chrome-stable(不是chromium)安装-chrome.sh。它可以从fedoraproject提取包并将这些包安装到/opt/谷歌/chrome/lib。我安装了chromedriver2.9 follow链接。我可以不出错地手动运行google-chrome和chromedriver。我通过pip安装selenium(selenium 2.41)。Selenium安装到/usr/lib/python2.6/站点包/。以这种方式安装的Google-chrome似乎不允许作为root用户打开。
When I run code under python console with non root user as follow:
当我在python控制台运行代码时,不使用root用户,如下所示:
>>> from selenium import webdriver
>>> driver = webdriver.Chrome()
It return error message as follow instead of openning chrome.
它返回如下所示的错误消息,而不是打开chrome。
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/usr/lib/python2.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 65, in __init__
keep_alive=True)
File "/usr/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 72, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 115, in start_session
'desiredCapabilities': desired_capabilities,
File "/usr/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 166, in execute
self.error_handler.check_response(response)
File "/usr/lib/python2.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u'unknown error: Chrome failed to start: crashed\n (Driver info: chromedriver=2.9.248304,platform=Linux 2.6.32-358.el6.x86_64 x86_64)'
I get log follow linkUnknown error: Chrome failed to start: exited abnormally. There is no solution on that link. What should I do? Thanks.
我得到日志跟踪链接未知错误:Chrome失败启动:异常退出。那个环节没有解决办法。我应该做什么?谢谢。
[0.987][INFO]: COMMAND InitSession {
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions": {
"args": [ ],
"extensions": [ ]
},
"javascriptEnabled": true,
"platform": "ANY",
"version": ""
},
"sessionId": null
}
[0.987][INFO]: Populating Preferences file: {
"alternate_error_pages": {
"enabled": false
},
"autofill": {
"enabled": false
},
"browser": {
"check_default_browser": false
},
"distribution": {
"import_bookmarks": false,
"import_history": false,
"import_search_engine": false,
"make_chrome_default_for_user": false,
"show_welcome_page": false,
"skip_first_run_ui": true
},
"dns_prefetching": {
"enabled": false
},
"profile": {
"content_settings": {
"pattern_pairs": {
"https://*,*": {
"media-stream": {
"audio": "Default",
"video": "Default"
}
}
}
},
"default_content_settings": {
"geolocation": 1,
"mouselock": 1,
"notifications": 1,
"popups": 1,
"ppapi-broker": 1
},
"password_manager_enabled": false
},
"safebrowsing": {
"enabled": false
},
"search": {
"suggest_enabled": false
},
"translate": {
"enabled": false
}
}
[0.988][INFO]: Populating Local State file: {
"background_mode": {
"enabled": false
},
"ssl": {
"rev_checking": {
"enabled": false
}
}
}
[0.988][INFO]: Launching chrome: /opt/google/chrome/google-chrome --disable-background-networking --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-hang-monitor --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --full-memory-crash-report --ignore-certificate-errors --load-extension=/tmp/.com.google.Chrome.NnyvZ9/internal --logging-level=1 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12775 --safebrowsing-disable-auto-update --safebrowsing-disable-download-protection --use-mock-keychain --user-data-dir=/tmp/.com.google.Chrome.AtCYvH data:,
[0.989][DEBUG]: DevTools request: http://127.0.0.1:12775/json/version
[0.991][WARNING]: PAC support disabled because there is no system implementation
[1.034][DEBUG]: DevTools request failed
[1.084][DEBUG]: DevTools request: http://127.0.0.1:12775/json/version
[1.085][DEBUG]: DevTools request failed
[1.135][DEBUG]: DevTools request: http://127.0.0.1:12775/json/version
[1.136][DEBUG]: DevTools request failed
.....
.....
[61.022][DEBUG]: DevTools request: http://127.0.0.1:12775/json/version
[61.024][DEBUG]: DevTools request failed
[61.024][INFO]: RESPONSE InitSession unknown error: Chrome failed to start: crashed
[61.025][DEBUG]: Log type 'driver' lost 0 entries on destruction
[61.025][DEBUG]: Log type 'browser' lost 0 entries on destruction
I am confused about those DevTools
things, either.
我也对DevTools的东西感到困惑。
1 个解决方案
#1
1
Are you using headless? If so, you will have to specify the headless display through pyvirtualdisplay
.
你用无头吗?如果是,您必须通过pyvirtualdisplay指定无头显示。
I had the same error (log) when I was running selenium headless without telling selenium to use visual display. After installing pyvirtualdisplay
, the following code works for me:
当我运行selenium headless而不告诉selenium使用可视显示时,我也有相同的错误(日志)。安装完pyvirtualdisplay后,我的工作代码如下:
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Chrome()
driver.get("http://www.google.com")
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()
#1
1
Are you using headless? If so, you will have to specify the headless display through pyvirtualdisplay
.
你用无头吗?如果是,您必须通过pyvirtualdisplay指定无头显示。
I had the same error (log) when I was running selenium headless without telling selenium to use visual display. After installing pyvirtualdisplay
, the following code works for me:
当我运行selenium headless而不告诉selenium使用可视显示时,我也有相同的错误(日志)。安装完pyvirtualdisplay后,我的工作代码如下:
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Chrome()
driver.get("http://www.google.com")
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()