I still vividly remember the first time I encountered the infamous chromedriver executable needs to be in path error. I was knee deep in building an intricate web scraping pipeline to extract leads from an real estate listings site. Hundreds of lines of beautiful Selenium code to elegantly traverse DOM elements, carefully constructed using CSS selectors and XPath expressions. With the finishing touches in place, I ran the script with bated breath, hoping to feast my eyes on a heap of structured lead data... only to be greeted by this befuddling message screaming back at me -
My elation quickly turned into head-scratching frustration. ChromeDriver? Executable? Path? As a coding newbie back then, these terms seemed like arcane incantations to me. I had very little visibility into environment configuration concepts that seasoned developers take for granted. This article is meant to spare you similar grief by clearly explaining exactly what this error means, and systematically providing surefire solutions to eliminate it as a blocker.
Whether you're an expert web scrapper seeking reliable remedies, or a Python initiate diving into browser automation, you'll uncover comprehesive guidance so Chrome and Chromedriver play nice in perfect harmony. Let's get cracking!
Chromedriver 101 - Your Essential Primer
Before diving deep on configurations, it's prudent get crystal clear on what Chromedriver is and why it matters.
In simple terms, Chromedriver is an executable file that's critical for allowing Selenium scripts to control Google Chrome. It essentially serves as the adapter between Selenium and Chrome, enabling commands to get seamlessly passed from your Python / Java / C# code down into browser actions rendered faithfully.
Here's a 60 second high level overview of how all the pieces play together:
Now what exactly does this error signifying Chromedriver not being in PATH mean?
To explain that properly, we need to take a quick detour to understand PATH itself under the hood.
Demystifyling PATH - Your OS Environment's "Known Addresses"
You can imagine PATH as simply a collection of known addresses your operating system maintains to locate vital executables essential for smooth functioning.
Some typical contents housed in PATH include directories containing critical system binaries, shells, utilities etc that let you efficiently run commands without requiring full absolute paths to these resources explicitly every time.
For example, you can simply execute
Your OS is smart enough to scan directories living within the PATH, find
Hopefully it's clearer now why our dear friend Chromedriver also needs to be listed in PATH for direct access.
When Selenium scans PATH while attempting automation and doesn't find Chromedriver parked there, it throws this error indicating it simply couldn't locate the crucial translator required to bridge conversations to Chrome.
Alright, now that we've got the conceptual foundation covered, let's shift gears into solutions so you never have to face this nemesis again!
Round One : Manually Installing and Configuring Chromedriver
While the methods in upcoming sections automate Chromedriver installation elegantly, I suggest scrappers first go through the manual flow initially before layering on sophistication.
Getting exposure on where executables need to be downloaded from, how central system variables work, and compatibilities between component versions is invaluablecontext upfront. Once comfortable with core concepts, automation libraries can be leveraged to simplify tooling administration going forward.
Let's walk through things step-by-step:
Step 1 : Downloading the Correct Chromedriver Version
The very first step is ensuring you have Chromedriver binary matching the exact Chrome version installed on your system. Even minor version mismatches can cause headaches, so precision here is critical.
Visit https://chromedriver.chromium.org/downloads and note down the Chrome version you currently have by clicking the 3-dot menu -> Help -> About Google Chrome.
Now download the Chromedriver package matching your Chrome version and OS flavor (Windows, Mac, Linux) for later installation.
Step 2: Installing Chromedriver
Unzip the downloaded Chromedriver package and you'll find the executable binary, typically named
Place this executable inside any folder structure of choice, for example in
Time to tell your OS where to find this Chrome intermediary!
Step 3: Adding Chromedriver Path to Your System's PATH
This is where things diverge slightly across Windows, Mac and Linux.
Press Windows key, type "env" and choose "Edit environment variables for your account". Under User Variables section, double click on PATH and click New to append the full folder path to the Chromedriver executable, e.g
On Mac / Linux:
Source the file for changes to reflect instantly in your terminal.
With this step, your OS should now be able to locate Chromedriver when Selenium attempts Chrome automation!
Let's add the final sprinkle with sample test code.
Step 4: Running Selenium Test Code
Here is boilerplate code to validate smooth Chrome automation powered by Chromedriver:
from selenium import webdriver
driver = webdriver.Chrome() # driver initialized to leverage Chromedriver automatically
driver.get("<http://google.com>") # navigates Chrome to google.com
print(driver.title) # prints page title to validate Chrome browsed properly!
If you see the page title printed successfully, Chromedriver and Chrome are best friends through Selenium thanks to your diligent installations & PATH additions!
Phew, what an adventure! While the above steps equip you to manually configure Chromedriver binding, they do entail repetitive mechanical steps each time.
Setting up environment variables correctly and hunting executable versions routinely can drain precious time and energy you should conserve for actual scraping coding.
Can we be smarter and simplify tooling administration? Darn right we can! Let's check out some sleek alternatives.
Round Two: Automagical Installation and Configuration Libraries
The Python ecosystem contains fantastic libraries that abstract away the heavy lifting discussed above reliably across platforms and browsers. Let's explore two extremely popular options - webdriver_manager and chromedriver_autoinstaller.
webdriver_manager : All Drivers Managed
As the name suggests, this nifty tool downloads and configures required webdriver binaries automatically for compatible browsers.
Installation is a quick
Now starting up Selenium for Chrome turns magically concise:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
# That's it! No manual exe downloads or PATH variable editing needed!
Here webdriver_manager behind the scenes:
You get to focus on actual test code rather than administrative hiccups!
chromedriver_autoinstaller : Just For Chrome
As the name hints, this package exclusively centers on streamlining Chromedriver configuration to automate Chrome specifically:
from selenium import webdriver
chromedriver_autoinstaller.install() # Checks if ChromeDriver exists already, grabs correct version if missing!
driver = webdriver.Chrome() # That's it! Begin Chrome automation sans any manual installation!
Under the hood, upon first invocation,
For Chrome-centric test suites, this simplicity can be handy versus the sometimes overengineering within webdriver_manager tackling all browsers.
Bonus: Selenium 4.6+ Manages Drivers Out of The Box!
Recently in late 2022, Selenium team introduced built-in automated driver management capabilities within Selenium itself!
If Selenium cannot locate valid ChromeDriver, GeckoDriver etc in PATH during test runs post v4.6+, it simply:
This means for common cases, you may not need any external libraries! Vanilla Selenium installation suffices - driver management happens transparently under the hood!
# Following now just works after Selenium v4.6+! No manual exe download or PATH config needed!
from selenium import webdriver
driver = webdriver.Chrome()
# Selenium will auto grab valid Chromedriver if not already available during execution!
I'd still advocate at least being aware of standalone tools like webdriver_manager and chromedriver_autoinstaller for advanced management. But Selenium's evolution positively impacts simplicity here for the general case!
Chrome + Chromedriver Version Parser Errors
Let's expand troubleshooting a bit more given intricacies around version pairings. Even if Chromedriver is correctly configured, you may face cryptic tracebacks like:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 101
Current browser version is 100.0.4896.60 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
This simply indicates the Chromedriver version you have installed is incompatible with the Chrome browser application itself. Just like Selenium server bindings have to match programming language versions, Chromedriver binaries need to match Chrome browser installs.
The key once again lies in aligning versions precisely. Follow the initial steps outlined earlier to download the matching ChromeDriver flavor and correctly configure its path - now errors around supported version syntax should vanish!
Plan to revisit downloads only when Chrome itself is upgraded / downgraded. Getting into lockstep cadence will eliminate frustrating mismatches!