Justin Benfit
Justin Benfit

Reputation: 483

'chromedriver' executable needs to be in PATH.' after adding chromedriver to my PATH

I have spent hours trying to get this working to no avail. I am trying to run this test script:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.nytimes.com")
headlines = driver.find_elements_by_class_name("story-heading")
for headline in headlines:
    print(headline.text.strip())

I have installed selenium and downloaded chromedriver as well as adding it to my PATH using sudo nano /etc/paths and adding entering the path /Users/Myname/Desktop/chromedriver. I closed out the terminal and checked it using echo $PATH and that path showed in my PATH so I'm sure it's there and /Users/Myname/Desktop/chromedriver is the location of my chromedriver exe file. However when I run the .py script above it returns "'chromedriver' executable needs to be in PATH." and I don't know what else to try.

Any help would be greatly appreciated. Thanks!

Upvotes: 0

Views: 375

Answers (1)

Aryan
Aryan

Reputation: 1113

You have to add the actual path to the *.exe or chromedriver.exe in the function call, there is no need to add it to your PC's PATH variable.

NOTE: Just to clarify, for example

driver = webdriver.Chrome("/Users/Myname/Desktop/chromedriver.exe") # In Actual Add The Path To chromedriver.exe or whatever *.exe in here

Only you can know where you exe is located so just add the exe path in the function rest it will be done for you.

Happy Coding!

Upvotes: 1

Related Questions