0

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

GeorgeDouj88
  • 49
  • 3
  • 11

3 Answers3

2

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.

James G
  • 2,069
  • 16
  • 28
  • I'm 100% sure this worked because I did this and forgot to change the driver to the new directory and it didn't work and then I did Felipe's solution and that worked so yours might have worked too. – GeorgeDouj88 Nov 26 '18 at 04:10
1

Try this setup:

# Setup our chrome preferences.
chromeOptions = webdriver.ChromeOptions()
# Change this variable to the path of the chromedriver you downloaded.
chromedriver = "D:\Downloads\chromedriver_win32\chromedriver.exe"

driver = webdriver.Chrome( executable_path = chromedriver, 
chrome_options = chromeOptions )
Felipe Gutierrez
  • 675
  • 6
  • 17
1

For me personally, it was a matter of restarting the machine after setting my environment variables. I know this sounds crazy, but for me, it worked.

I understand that this question was resolved already. I just thought I'd provide my own input for anyone that comes across this question in the future.

dommie123
  • 11
  • 1