1

I am trying to setup Chromedriver using selenium in Jupyter notebook. I have also setup environment variables in my Windows 10 system where chromedriver.exe located, but still I am getting below shown error.

Here is my code:

# Import Libraries
import pandas as pd
import selenium
import os
from selenium import webdriver
chrome_path = r"C:\Users\Klsingh\Desktop\chromedriver.exe"

wd = webdriver.Chrome()
wd.get(url)

Below is the error which I get, have tried several method but still unable to resolve it.

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
/opt/conda/envs/Python36/lib/python3.6/site-packages/selenium/webdriver/common/service.py in start(self)
     75                                             stderr=self.log_file,
---> 76                                             stdin=PIPE)
     77         except TypeError:

/opt/conda/envs/Python36/lib/python3.6/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
    728                                 errread, errwrite,
--> 729                                 restore_signals, start_new_session)
    730         except:

/opt/conda/envs/Python36/lib/python3.6/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1363                             err_msg += ': ' + repr(err_filename)
-> 1364                     raise child_exception_type(errno_num, err_msg, err_filename)
   1365                 raise child_exception_type(err_msg)

FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'

During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)
<ipython-input-44-03162065f481> in <module>
----> 1 wd = webdriver.Chrome()
      2 wd.get(url)

/opt/conda/envs/Python36/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
     71             service_args=service_args,
     72             log_path=service_log_path)
---> 73         self.service.start()
     74 
     75         try:

/opt/conda/envs/Python36/lib/python3.6/site-packages/selenium/webdriver/common/service.py in start(self)
     81                 raise WebDriverException(
     82                     "'%s' executable needs to be in PATH. %s" % (
---> 83                         os.path.basename(self.path), self.start_error_message)
     84                 )
     85             elif err.errno == errno.EACCES:

WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

I am trying to execute the above code on a online server not on my desktop or IDE. Please help.

Thanks, Kumar

Klsingh
  • 17
  • 5

2 Answers2

1

As you are using the raw switch i.e. r you need to enclose the absolute path of the WebDriver variant within single quotes i.e. '...' and pass it while invoking webdriver.Chrome() through the Key executable_path as follows:

So, effectively your line of code will be:

chrome_path = r'C:\Users\Klsingh\Desktop\chromedriver.exe'

wd = webdriver.Chrome(executable_path=chrome_path)

Alternatively, you can achieve the same in a single line as follows:

wd = webdriver.Chrome(executable_path=r'C:\Users\Klsingh\Desktop\chromedriver.exe')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Still I am getting File not found error, is it related to remote interpreter which I am using? – Klsingh Jan 27 '20 at 09:10
  • I am using Microsoft Azure to run Python Jupyter notebooks in browser, please suggest how to resolve this error - **WebDriverException: Message: 'C:\Users\Klsingh\Desktop\chromedriver.exe' executable needs to be in PATH**. I have already added the path in my local system's environment variable. – Klsingh Jan 28 '20 at 06:36
  • this answer is helpful for local environment when anyone is using IDE on their laptop or desktop. This answer is not applicable for Azure or IBM Watson environment. – Klsingh Jan 29 '20 at 10:12
0

I had to same issue and just resolved it on desktop.

If you're using Windows subsystem for linux or something similar, make sure the path is typed correctly and accessible from the OS.

For example, in my case in WSL, /mnt/c/users/documents instead of C:/users/documents

lkal
  • 25
  • 1
  • 5