Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome failed to start on CentOS using chromedriver2.9

Env: chromedriver 2.9, google-chrome-stable 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.

When I run code under python console with non root user as follow:

>>> from selenium import webdriver
>>> driver = webdriver.Chrome()

It return error message as follow instead of openning 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.

[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.

like image 566
Nick Dong Avatar asked May 14 '14 11:05

Nick Dong


People also ask

Does selenium WebDriver work with Chrome?

Setting up your system to allow a browser to be automated. Through WebDriver, Selenium supports all major browsers on the market such as Chrome/Chromium, Firefox, Internet Explorer, Edge, and Safari.


1 Answers

Are you using headless? If so, you will have to specify the headless display through 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:

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()
like image 81
Winston Chen Avatar answered Sep 24 '22 15:09

Winston Chen