简体   繁体   中英

Selenium Chrome Driver Under Linux

Having a bit of a rough time trying to get a webdriver spawning under Linux.

I'm on CentOS 7.3 I've installed Chrome, Chromium and a host of other python libs. I'm running:

chrome_options = webdriver.ChromeOptions()
thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options)

The alternative with a different path runs fine under Windows so the problem is definitely in my port to Linux.

I've ran:

chmod a+x chromedriver

And it runs under root so it should have access to the chromedriver.

If I spawn it through a threadpool with a timeout it hits that timeout every time. Running it normally it eventually throws an error:

 Traceback (most recent call last):
  File "Skyscrapercomp.py", line 492, in <module>
    thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.10.0-514.2.2.el7.x86_64 x86_64)

My takeaway here was "Chrome failed to start: exited abnormally" which doesn't give me a lot to go on.

I've used pip to install the latest Selenium and Yum to install Chromium and Chrome. Feeling a bit dead in the water not sure what my next step is so I'd really appreciate a prod in the right direction.

/Updates:

I checked in /usr/bin google-chrome is there which is the default location it wants.

Also tried putting the chromedriver into /usr/bin and not giving it a location:

TheBrowser = webdriver.Chrome()
TheBrowser.get("http://www.google.com")
print TheBrowser.page_source.encode('utf-8')

But this gives the same error.

Try to use logging to find the problem:

chrome_options = webdriver.ChromeOptions()
service_log_path = 'chromedriver.log'
service_args = ['--verbose']

thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options, service_args=service_args, service_log_path=service_log_path)

In my case there was an error with display (no X11 on my Ubuntu server). This helped me:

from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()  # don't forget to .stop() it at the end of program

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM