You fire up your Selenium-based Chrome browser automation operation(s) one fine day and you are greeted with a godawful bit of an exception, at the bottom of which you read the following:
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
Puzzled, “It was working optimally just yesterday!”, you think to yourself, wondering what the variable causing this could be. The infamously trusty Stack Overflow does not tell you much about this, except that you probably need to explicitly set the Google Chrome binary’s path as so:
chromeOptions = webdriver.ChromeOptions()
chromeOptions.binary_location = "C:\Program
Files\Google\Chrome\Application" chromeDriver = "/chromedriver.exe"
driver = webdriver.Chrome(chromeDriver, options=chromeOptions)
But, “dude”—you ask yourself—”why should I explicitly set the Google Chrome binary’s path?” or maybe “Why was this not required just yesterday?”
Well, for the curious minds that made it here, may you have the strength of a thousand Suns, for we are a different people that consist of special gears in our heads that start “churning” once an inconsistency makes its way into our lives; and instead of just “fixing” the capsizing ship with a chunky roll of Flex tape (not sponsored) over the cracks and holes, we would like to know how it happened, what made it happen, and why it happened—as we abandon ship and auto-inflate our enormous life raft (using Selenium, of course, ’cause “automation”) and then sail off into the sunset as we code an Apache helicopter into existence (what ship? Pfft).
“Now if there’s one thing you can be sure of, it’s that nothing is more powerful than a young boy’s wish. Except an Apache helicopter. An Apache helicopter has machine guns AND missiles. It is an unbelievably impressive complement of weaponry, an absolute death machine.” —Morgan-Freeman-sounding-but-not-Morgan-Freeman narrator — Ted (2012)
We have digressed far into the 3.5th dimension here; apologies, here’s the reason and possible fix!
NOTE: Just for the sake of clarity, this “Chrome binary” that Selenium is referring to is simply the OG big daddy main “Chrome.exe” file located in Google Chrome’s installation directory.
In previous versions of Google Chrome (v84 and below), Google Chrome’s default installation path—where “Chrome.exe” typically is—used to be:
But since the newer iteration(s) (v85 and above), the default installation path is:
Now, this is the problem. Where the older chromedriver.exe versions (v84 and below) intuitively expect the Chrome binary to be is in the former path, not the latter. If your Google Chrome browser naturally auto-updated from v84 to v85, this path remains unchanged (so chromedriver.exe has no issues navigating to it). However, if you explicitly installed or reinstalled Google Chrome on the latest version (v85 and above) recently, then the installation path changes to the newer one, and so, your older chromedriver.exe is not able to navigate to the Chrome binary; and this makes your code end with that particular “cannot find Chrome binary” exception. Ergo, this is why you are having to explicitly set the “binary_location” to the latter manually
NOTE: Since Google Chrome does not allow customizing the installation path while installing and just directly installs into Program Files by default, We have already tried a workaround and changed the default installation path itself from the registry (regedit); but to no avail, Google Chrome would then completely refuse to work once installed in the desired directory. It seems newer Google Chrome installations can only function if they are installed in the newer installation path.
Download the latest chromedriver.exe version that corresponds to your Google Chrome version (from here), and replace your existing chromedriver.exe with this new one.
Your problem should now be solved, since the newer chromedriver.exe is equipped with the knowledge that the new Google Chrome installation path is where it is supposed to look in order to find the Chrome binary.
But—for whatever reason—if you do not want to upgrade the chromedriver.exe version, you could just downgrade your Google Chrome version by obtaining an older version that corresponds to your chromedriver.exe version, uninstalling the newer version, and then installing the older version you had obtained.
NOTE: You will not find any official downloads for older Google Chrome versions since Google does not allow this for security reasons, but you may find some unofficial sources like this (personally tested and verified, safe). Also be informed that upon installing an older version of Google Chrome, auto-updates will no longer work anymore; so the only way for a potential future update would be via an uninstall and manual install of the latest Google Chrome version.