Selenium chromedriver PATH error doesn't resolve

Issue

So I’ve been trying to follow this YouTube tutorial (https://www.youtube.com/watch?v=BGU2X5lrz9M) as a quick fun project to introduce myself to selenium, but I’ve already run into a problem. Whenever I run my code, I keep getting this error: ‘chromedriver’ executable needs to be in PATH. I’ve searched up the problem many times, moved chromedriver.exe to the C:/ directory to make things easier, and did all I can with the enviroment variables and still can’t figure this out. Please help me out!
Here’s the code I’m running

# This bot is made following this YouTube tutorial: https://www.youtube.com/watch?v=BGU2X5lrz9M
# All the import crap
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time


driver = webdriver.Chrome("C:\\chromedriver.exe")


class InstaBot:

    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.driver = webdriver.Chrome()

    def close_browser(self):
        self.driver.close()

    def login(self):
        global driver
        driver = self.driver
        driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher")
        time.sleep(2)
        # "//a[@href'accounts/login']"
        # "//input[@name='username']"
        # "//input[@name='password']"


georgeIG = InstaBot("NotGonnaShowToStackOverflow", "NotGonnaShowToStackOverflow")
georgeIG.login()

Here’s what I’ve tried with the environment variables.
enter image description here

enter image description here

Solution

In the video you linked to, the command pip install selenium will have handled the addition of the driver to the path.

I’m assuming you have tried to emulate this on windows and you’re having trouble understanding how the PATH variable is used. This related question on SO discusses how to register a .exe so it is available globally, which may help you.

You cannot register an executable directly in your PATH variable as you have done, your PATH should only contain directories. Try moving your chromedriver.exe file into one of the folders in your PATH and run your commands again.

Alternatively, you could create a folder such as c:\buildtools, add that to your PATH and then put chromedriver.exe in that folder and run your commands again.

Answered By – James G

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published