Selenium: geckodriver executable needs to be in PATH?

Selenium is a popular web browser automation library used for web scraping. To run, however, Selenium needs special web browser executables called drivers. For example, to run Firefox web browser Selenium needs geckodriver to be installed. Without it a generic exception will be raised:

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

This can also mean that the geckodriver is installed but Selenium can't find it. To fix this the geckodriver location should be added to the PATH environment variable:

$ export PATH=$PATH:/location/where/geckodriver/is/

Alternatively, we can specify the driver directly in the Selenium initiation code:

from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
driver.get('https://scrapfly.io/')
Question tagged: Selenium, Python

Related Posts

How to Scrape With Headless Firefox

Discover how to use headless Firefox with Selenium, Playwright, and Puppeteer for web scraping, including practical examples for each library.

Selenium Wire Tutorial: Intercept Background Requests

In this guide, we'll explore web scraping with Selenium Wire. We'll define what it is, how to install it, and how to use it to inspect and manipulate background requests.

Web Scraping Dynamic Web Pages With Scrapy Selenium

Learn how to scrape dynamic web pages with Scrapy Selenium. You will also learn how to use Scrapy Selenium for common scraping use cases, such as waiting for elements, clicking buttons and scrolling.