Solve Selenium WebDriverException executable needs to be in PATH error message

Driving on the road
Image: Driving on the road (License: CC-BY-SA Marcelo Canina)

Works for Chrome (chromedriver), Firefox (geckodriver) and the rest of possible drivers available in Selenium

Published:
Last modified:
Tag Errors

Overview

Guide to use Selenium with the appropriate web driver.

In Selenium we have to choose a specific “browser” to use in our code, for example if we want to use Chrome:

from selenium.webdriver.chrome.webdriver import WebDriver

browser = WebDriver()

The above code expects that we already have the right drivers to execute the browser in our code, if not it will display an error message.

In this case we solve Selenium’s error message about not being able to find the desired set of capabilities used in our code: selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities.

Or when it can’t find the right webdriver it will show some of the following errors:

  • Using Chrome: selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
  • Using WebKitWebDriver: selenium.common.exceptions.WebDriverException: Message: 'WebKitWebDriver' executable needs to be in PATH.
  • Using Firefox: selenium.common.exceptions.GeckoDriverException: Message: GeckoWebDriver' executable needs to be in PATH.

Solution

The generic steps to solve this are:

  1. download the desired browser driver executable
  2. make Selenium aware of the above driver location

1. First alternative: Automatic

The easiest way is to use webdriver-manager1 which is a library “to automatically manage drivers for different browsers”.

1.1 Install

Install with the command: pip install webdriver_manager


$ pip install webdriver_manager
Collecting webdriver-manager
  Downloading webdriver_manager-2.4.0-py2.py3-none-any.whl (13 kB)
Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from webdriver-manager) (2.22.0)
Collecting crayons
  Using cached crayons-0.3.0-py2.py3-none-any.whl (4.6 kB)
Collecting configparser
  Using cached configparser-5.0.0-py3-none-any.whl (22 kB)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,1.26,=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->webdriver-manager) (1.25.6)
Requirement already satisfied: chardet3.1.0,=3.0.2 in ~/.local/lib/python3.6/site-packages (from requests->webdriver-manager) (3.0.4)
Requirement already satisfied: certifi=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->webdriver-manager) (2019.9.11)
Requirement already satisfied: idna2.9,>=2.5 in ~/.local/lib/python3.6/site-packages (from requests->webdriver-manager) (2.8)
Requirement already satisfied: colorama in /usr/local/lib/python3.6/dist-packages (from crayons->webdriver-manager) (0.4.1)
Installing collected packages: crayons, configparser, webdriver-manager
Successfully installed configparser-5.0.0 crayons-0.3.0 webdriver-manager-2.4.0

1.2 Use

In your code use the right manager for Selenium’s webdriver:

pip install webdriver-manager
from selenium import webdriver

And then Choose the right browser

Chrome

For Chrome:

from webdriver_manager.chrome import ChromeDriverManager

browser = webdriver.Chrome(ChromeDriverManager().install())

Firefox

For Firefox:

from webdriver_manager.firefox import GeckoDriverManager
browser = webdriver.Firefox(executable_path=GeckoDriverManager().install())

Internet Explorer

For IE:

from webdriver_manager.microsoft import IEDriverManager

browser = webdriver.Ie(IEDriverManager().install())

Edge

from webdriver_manager.microsoft import EdgeChromiumDriverManager

browser = webdriver.Edge(EdgeChromiumDriverManager().install())

2. Second alternative: Manual

If you don’t want to use an external package you can do it manually with one of these options.

First, download the right driver consulting your desired browser’s driver at: https://selenium-python.readthedocs.io/api.html

Then, one of these two alternatives:

  • add driver location to system’s path
    • PATH=/location/of/browserdriver:$PATH
  • specify the location via Webdriver’s executable_path parametern
    • driver = webdriver.Chrome(executable_path='/location/of/firefoxdriver)

References

Uruguay
Marcelo Canina
I'm Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.
comments powered by Disqus


How to solve Selenium error message when not having the appropriate web driver in Python/Django.

Clutter-free software concepts.
Translations English Español

Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.

Powered by SimpleIT Hugo Theme

·