Home >Backend Development >Python Tutorial >Why Doesn't My Selenium Code Find chromedriver Even After Setting the PATH Environment Variable?
When encountering the error "chromedriver' executable needs to be available in the path," despite manually adding the path to the executable in the Environment Variable "Path," there may be an issue with the approach taken.
The Outdated Method
Traditionally, setting up the chromedriver required downloading the binary and adding the path to the executable manually. While this method is still discussed in some places, it has become outdated.
Introducing WebDriver Manager
To streamline the process, WebDriver Manager has been developed. By installing WebDriver Manager using pip, the setup can be automated.
pip install webdriver-manager
Simplified Chrome Driver Setup
With WebDriver Manager installed, the code in the original question can be modified as follows:
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(ChromeDriverManager().install())
This code will automatically locate and download the appropriate chromedriver executable and manage its path, eliminating the need for manual configurations.
Extending to Other Browsers
WebDriver Manager can also be used to set up executable binaries for other browsers, such as Firefox, Edge, and Internet Explorer. For example:
from selenium import webdriver from webdriver_manager.firefox import GeckoDriverManager driver = webdriver.Firefox(GeckoDriverManager().install())
The above is the detailed content of Why Doesn't My Selenium Code Find chromedriver Even After Setting the PATH Environment Variable?. For more information, please follow other related articles on the PHP Chinese website!