1

I'm a new student of programmin and I'm trying to use Chromedriver and Selenium for the first time. I definitely can't access to the downloaded file, don't know why. This is my input:

from selenium import webdriver
driver = webdriver.Chrome(executable_path = "/Users/silvia/Desktop/executables/chromedriver")

As you can see below, the result I get is the following. Says there's no such file on my Desktop, but there is! I tried with backslash, double backslash and everything. Maybe I should try the whole process from the beginning! Any idea of why not working? Thank you in advance!

This is the error message:

------------------
FileNotFoundError                         Traceback (most recent call last)
/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/common/service.py in start(self)
     71             cmd.extend(self.command_line_args())
---> 72             self.process = subprocess.Popen(cmd, env=self.env,
     73                                             close_fds=platform.system() != 'Windows',

/opt/anaconda3/lib/python3.8/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, text)
    853 
--> 854             self._execute_child(args, executable, preexec_fn, close_fds,
    855                                 pass_fds, cwd, env,

/opt/anaconda3/lib/python3.8/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)
   1701                         err_msg = os.strerror(errno_num)
-> 1702                     raise child_exception_type(errno_num, err_msg, err_filename)
   1703                 raise child_exception_type(err_msg)

**FileNotFoundError: [Errno 2] No such file or directory: '/Users/silvia/Desktop/executables/chromedriver'**

During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)
<ipython-input-6-a1abac069770> in <module>
      1 from selenium import webdriver
      2 
----> 3 driver = webdriver.Chrome(executable_path = "/Users/silviafabbi/Desktop/executables/chromedriver.exe")

/opt/anaconda3/lib/python3.8/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/anaconda3/lib/python3.8/site-packages/selenium/webdriver/common/service.py in start(self)
     79 except OSError as err:
     80 if err.errno == errno.ENOENT:
---> 81 raise WebDriverException(
     82 "'%s' executable needs to be in PATH. %s" % (
     83 os.path.basename(self.path), self.start_error_message)

WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
YogiX
  • 51
  • 5
  • 1
    I always had this issue with chrome driver. So I will suggest you to use `webdriver_manage` so that you don't have to link the chrome driver executable script. – Pygirl Oct 21 '20 at 08:49

3 Answers3

3

Without giving executable path:

You can use webdriver_manage (install it by pip install webdriver_manager)

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options)
Pygirl
  • 12,969
  • 5
  • 30
  • 43
  • thank you! Now it says ValueError: Could not get version for Chrome with this command: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version Still trying the other ways suggested, without succes anyway :) I'll keeep trying – YogiX Oct 21 '20 at 11:04
  • 1
    Try: https://stackoverflow.com/questions/55201226/session-not-created-this-version-of-chromedriver-only-supports-chrome-version-7 – Pygirl Oct 21 '20 at 11:12
  • 1
    I have least idea about macos. I think issue is with the chrome version. – Pygirl Oct 21 '20 at 11:14
  • 1
    It was actually that. Many thanks for suggesting the right way! – YogiX Oct 22 '20 at 14:15
  • 1
    Glad it helped! Close the question by accepting the answer(clicking on tick) if answer helps :) – Pygirl Oct 22 '20 at 14:29
1

Silvia, try

C:/Users/silvia/Desktop/executables/chromedriver

or whatever your harddisk name it is

kennysliding
  • 2,783
  • 1
  • 10
  • 31
  • Thanks a lot! I tried with all possible names (MacintoshHD instead C:, Scrivania instead Desktop and so on....). Still doesn't work :( – YogiX Oct 21 '20 at 11:05
1

I dont know if you have already solved it, but this also happened to me and I realized that after downloading chromedriver I forgot to put the file inside the very same directory where python.exe is located. Usually, you can find your python.exe file by going to (C:) --> Users --> your User and finally anaconda3 directory (considering that you have installed anaconda package, which I highly recommend). Put your chromedriver file inside anaconda3 directory, which is the exact same place where you can find python.exe. And thats it! After doing this, I could run my code without a problem. Greetings from Brazil! ;)