2

Thisselenium.common.exceptions.WebDriverException: Message: '' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home problem arises when I try to run this code. I have downloaded the file from the link and unzipped the it to my download folder like shown: C:\Users\Alexandr\Downloads\chromedriver_win32 . Then I put the path to the executable binary (C:\Users\michael\Downloads\chromedriver_win32) into the Environment Variable "Path".

I found the same thread on StackOverflow and they say I should type chromedriver in cmd and get something like this tarting ChromeDriver 2.15.322448, in my case I get "chromedriver" is not inner or outer command(this was a translation from my native language). What should I do in this case

from selenium import webdriver
from time import sleep

class InstaBot:

    def __init__(self, username, password):
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.instagram.com/?hl=ru')
        sleep(2)
        self.driver.find_element_by_xpath("//input[@name=\"username\"]") \
            .send_keys(username)
        self.driver.find_element_by_xpath("//input[@name=\"password\"]") \
            .send_keys(password)
        self.driver.find_element_by_xpath('//button[@type="submit"]') \
            .click()
        sleep(4)
        self.driver.find_element_by_xpath('//button[contains(text()."Не сейчас")]').click()


InstaBot('_max_leva_', here is my password)

This is error code:

C:\Users\Alexandr\AppData\Local\Programs\Python\Python38-32\python.exe C:/PythonProjects/python/LearningPython/main1.py
Traceback (most recent call last):
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Не удается найти указанный файл

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/PythonProjects/python/LearningPython/main1.py", line 27, in <module>
    InstaBot('_max_leva_', '447781470659')
  File "C:/PythonProjects/python/LearningPython/main1.py", line 14, in __init__
    self.driver = webdriver.Chrome()
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\Alexandr\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home


Process finished with exit code 1

Environment Variable:

%PATH%:C:\Users\Alexandr\Downloads\chromedriver_win32

Vy Do
  • 46,709
  • 59
  • 215
  • 313
Maksim Levchenko
  • 87
  • 1
  • 1
  • 9
  • 1
    you can check if that path is available when you ```import os``` and then ```print(os.environ['PATH'])``` in your code. – ewokx Jul 14 '20 at 23:50
  • You need to set path , seems like in error there is no chromedriver file – Justin Lambert Jul 15 '20 at 00:06
  • after setting `PATH` you should check if you can run `chromedriver.exe` in console/terminal in any folder (without full path to `chromedriver.exe`). – furas Jul 15 '20 at 06:27
  • BTW: as I remeber in Windows you have to use `;` in `PATH` to separate paths but you use `:` which is used in `Linux` - `%PATH%;C:\Users\Alexandr\Downloads\chromedriver_win32` – furas Jul 15 '20 at 06:29

1 Answers1

2

In the self.driver = webdriver.Chrome(), pass the path to the executable as an argument in the parentheses.

For example:

self.driver = webdriver.Chrome('C:/user/Downloads/chromedriver.exe')

RushiSrinivas.K
  • 171
  • 2
  • 11