Selenium: geckodriver executable needs to be in PATH?

You need to make sure that the geckodriver executable is available in your PATH. Otherwise, Selenium will throw this error:

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

The best way to fix this error is to use the webdriver-manager package. It will make sure that you have a valid geckodriver executable in PATH and if it is not available, it will download it automatically. You can install it using PIP:

$ pip install webdriver-manager

And use it in your Python code like this:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))

# Open Scrapingbee's website
driver.get("http://www.scrapingbee.com")

The code might take a second or two on the initial run as it has to download the geckodriver binary. Successive runs should be a lot faster.

Related Selenium web scraping questions: