-1

while running any selenium code it shows this I have even added chromedriver.exe to my directory but still this error comes up

  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\Programming\Python\Projects\_Acoustify_\Scrapping bots\amazon_bot_2.py", line 4, in <module>
    driver = webdriver.Chrome()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\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
Vansh Khera
  • 45
  • 1
  • 9
  • What directory is `chromedriver.exe` in? It has to be on your PATH – will-hedges May 11 '21 at 15:24
  • How did you initialize the driver ? – cruisepandey May 11 '21 at 17:27
  • 1
    @chemicalwill Thank you so much earlier the chromedriver was in my project directory but not in the directory which I am working in, Thank you so much :) – Vansh Khera May 13 '21 at 12:10
  • @VanshKhera I'm glad to hear it! You can keep chromedriver in your directory, you just have to pass it to `webdriver.Chrome('/path/to/chromedriver')` – will-hedges May 13 '21 at 12:18
  • Does this answer your question? [selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH error with Headless Chrome](https://stackoverflow.com/questions/46085270/selenium-common-exceptions-webdriverexception-message-chromedriver-executabl) – demouser123 May 13 '21 at 12:26

1 Answers1

0

In the last line of the error, you have to have chromedriver in PATH.

If you want to keep it in your project directory, add the path for chromedriver to your webdriver call:

driver = webdriver.Chrome('/path/to/chromedriver')
will-hedges
  • 1,254
  • 1
  • 9
  • 18