Headless browser: 'chromedriver' executable needs to be in PATH


#1

I am a newbie and I am trying to use a headless browser. I installed google-chrome-stable install, firefox, and xvfb.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get(“http://www.python.org”)
assert “Python” in driver.title
elem = driver.find_element_by_name(“q”)
elem.clear()
elem.send_keys(“pycon”)
elem.send_keys(Keys.RETURN)
assert “No results found.” not in driver.page_source
driver.close()

I have tried with both firefox and chrome and have got the following error (only it is geckodriver it cannot find).

Traceback (most recent call last):
  File "/home/ubuntu/workspace/selenium_script.py", line 4, in <module>
    driver = webdriver.Chrome('/path/to/chromedriver')  # Optional argument, if not specified will search path.
  File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0.b3-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0.b3-py2.7.egg/selenium/webdriver/common/service.py", line 71, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x7f9df479afd0>> ignored

If I specify the path, like so:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome('/usr/bin/google-chrome-stable')  # Optional argument, if not specified will search path.
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

I get the following error:

Traceback (most recent call last):
  File "/home/ubuntu/workspace/selenium_script.py", line 4, in <module>
    driver = webdriver.Chrome('/usr/bin/google-chrome-stable')  # Optional argument, if not specified will search path.
  File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0.b3-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0.b3-py2.7.egg/selenium/webdriver/common/service.py", line 86, in start
    self.assert_process_still_running()
  File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0.b3-py2.7.egg/selenium/webdriver/common/service.py", line 99, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome-stable unexpectedly exited. Status code was: 1

Please help.