. Advertisement .
..3..
. Advertisement .
..4..
One of the most popular Web automation tools in the IT sector today is Selenium. New Selenium versions are released as time goes on, new features are routinely added, and the user base continues to grow. “Selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH” is a confusing problem that many programmers encounter. It shows up in many ways. What is the cause of it and how to fix it? Read this article to find the best solutions.
When Do You Get The Error “Selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH”?
When you run your program, you easily encounter the following error:
Selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH
What Are The Best Solutions For “Selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH” Error?
Solution 1: Set up and import the webdriver-manager module
To fix the Selenium error “Selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH”, you have to run pip install webdriver-manager
to set up and import the webdriver-manager
module. The module makes it easier to manage binary drivers for many browsers.
Now, in the root directory of project, let’s open your terminal and set up the webdriver-manager
module. Look at the following example:
# when using Python 2 or in a virtual environment
pip install webdriver-manager
# if you are using python 3 (could also be pip3.10 relied on your version)
pip3 install webdriver-manager
# If you get a sudo permissions error
pip3 install webdriver-manager
# if there is not pip in your PATH environment variable
python -m pip install webdriver-manager
# if you are using python 3 (could also be pip3.10 relied on your version)
python3 -m pip install webdriver-manager
# if you are using Anaconda
conda install -c conda-forge webdriver-manager
You can import the webdriver-manager package after you set up it and utilize it like the following:
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
driver.get("http://www.python.org")
driver.close()
Although the webdriver-manager
module can be used with any other browser, the above example demonstrates how to use it with the Firefox browser.
Following is an illustration of how the module is used with Chrome.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("http://www.python.org")
driver.close()
On the official PyPI website, you can see examples of how to use the webdriver-manager module with all other browsers.
Drivers for many browsers can be automatically managed with the help of the webdriver manager module. You must download the drivers’ binary files, unzip them on your computer, then set the path to the driver when using the class from the selenium module if you choose not to use the module.
You can call the install method on the particular driver manager by using the webdriver manager module, and it will work.
Solution 2: Install GeckoDriver manually
Another solution for you to solve the error “Selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH” is installing GeckoDriver manually. The user must manually configure GeckoDriver using this method, which is straightforward. Let’s follow these steps:
Step 1: Downloading GeckoDriver The first step is to use the following URL to get the driver: geckodriver.
Step 2: Installing GeckoDriver Installing the driver is required in the second step. To begin the installation process on your Mac, unzip the driver file. Move the driver to the desired spot after that. Make certain that you copied the driver’s Path.
Step 3: Mentioning the executable path
from selenium import webdriver
# Code 2
browser =
webdriver.Firefox(executable_path="/usr/local/Cellar/geckodriver/0.30.0/bin/geckodriver")
browser.get("https://app.finxter.com/")
After importing the relevant libraries, such as Selenium webdriver, run the script mentioned above. Mention the path of the GeckoDriver as indicated in Code 2 in the Firefox class. In our situation, it is:
/usr/local/Cellar/geckodriver/0.30.0/bin/geckodriver
The executable path has a record of this path.
The whole pathname of the user’s executable file is referred to as the executable path. You can now access the website https://app.finxter.com/ by using a driver.
When the module is executed, the driver object’s GeckoDriver Driver interacts with the Firefox browser. The browser will now open automatically as a result. You can add code to the web scrape the information you need, and store it in a CSV file.
Conclusion
The solutions mentioned above are the best options for those still confused with this error: “Selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH”. We hope that you can easily resolve your problem with these methods. If you need our support or have other questions, we have a thriving community where everyone is always willing to help. Finally, we wish you a productive day filled with new solutions and code.
Read more
Leave a comment