0

I'm trying to webscrape with Python and selenium, and I've run into an error like so:

Traceback (most recent call last):
  File "C:/Users/You/your_code.py", line 5, in <module>
    driver = webdriver.Chrome(executable_path='c:\path\to\windows\webdriver\executable.exe')
  File "C:\Users\You\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\You\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'executable.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

It seems like I haven't installed chromedriver for selenium properly. How do I install chromedriver properly for selenium?

marsnebulasoup
  • 2,530
  • 2
  • 16
  • 37

1 Answers1

1

There are a few ways you can go about this:

Using Chocolatey

The easiest way I've found to install chromedriver is to use chocolatey. You can follow the instructions to install it here, and once it's installed, just run choco install chromedriver (as an administrator), and it should install chromedriver for your version of chrome.

Then in your code, just remove the reference to chromedriver's path:

Before:

driver = webdriver.Chrome(executable_path='c:\path\to\windows\webdriver\executable.exe')

After:

driver = webdriver.Chrome()

Manually

If you don't want to use chocolatey, then follow these steps

  1. Go to chrome://version/ in Chrome, to check your current version. As you can see it's version 89 for me:

version

  1. Go to chromedriver.chromium.org/downloads and download the version of chromedriver that's the same as your browser version:

chromedriver

  1. Download the right version for your OS. For example, if you are using Windows, download the win_32 one:

download

  1. Extract the .ZIP and place chromedriver.exe in the same folder as your Python program:

  1. Change the path to chromedriver to just chromedriver.exe:

Before:

driver = webdriver.Chrome(executable_path='c:\path\to\windows\webdriver\executable.exe')

After:

driver = webdriver.Chrome(executable_path='chromedriver.exe')

...and you should be good to go.


Adding chromedriver to the PATH

If you want to add chromedriver to the PATH so you don't have to worry about where chromedriver is each time you write a selenium program, then it'd be a good idea to just use chocolatey, because it should install it globally. It's also much easier, so go with that if you can. However, you can still set chromedriver to the PATH manually, following these steps (for Windows):

  1. Open Command Prompt. Create a directory at C:\bin by running
cd /

...then:

mkdir bin

...then:

cd bin

...then:

explorer .

This should open the folder in File Explorer:

bin

  1. Place chromedriver.exe in this folder
  2. Set it to the PATH by running, in Command Prompt:
setx PATH "%PATH%;C:\bin"

You should get something like this:

done

  1. Close and reopen Command Prompt
  2. Verify setup by running chromedriver -v. You should get something like this:
C:\Users\You>chromedriver -v
ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

If so, you're all done.

Instructions for adding to PATH were adapted from here. For other operating systems, see here.

marsnebulasoup
  • 2,530
  • 2
  • 16
  • 37