'Drivers for selenium will not work 'chromedriver' executable needs to be in PATH

Very new to this, and I cannot get chromedriver or geckodriver to work. They are both located in /usr/local/bin/. So I know they are in PATH.

My code:

from selenium import webdriver

driver = webdriver.Chrome('/usr/local/bin/chromedriver')  
driver.get('http://www.google.com/xhtml');

Here what I get back:

Traceback (most recent call last):   File "11.py", line 3, in <module>
    driver = webdriver.Chrome('Desktop/chromedriver')  # Optional argument, if not specified will search path.   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
    self.service.start()   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 81, 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


Solution 1:[1]

You have to pass the absolute path of the ChromeDriver along with the Attribute Key as follows :

from selenium import webdriver

driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')  
driver.get('http://www.google.com');

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 undetected Selenium