Selenium ошибка cannot find chrome binary

This error message…

WebDriverException: unknown error: cannot find Chrome binary

…implies that the ChromeDriver was unable to find the Chrome binary in the default location for your system.

As per the ChromeDriver — Requirements:

The server expects you to have Chrome installed in the default location for each system:

OS Expected Location of Chrome
Linux /usr/bin/google-chrome1
Mac /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Windows XP %HOMEPATH%Local SettingsApplication DataGoogleChromeApplicationchrome.exe
Windows Vista and newer C:Users%USERNAME%AppDataLocalGoogleChromeApplicationchrome.exe

1 For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.


Using a Chrome executable in a non-standard location

However you can also override the default Chrome binary location as follows:

To use Chrome version 55.x installed in non standard location through ChromeDriver v2.26 you can use the following code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = "C:\Program Files\Chrome\chrome64_55.0.2883.75\chrome.exe"
driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:pathtochromedriver.exe')
driver.get('http://google.com/')
print("Chrome Browser Invoked")
driver.quit()

Related Docs


Reference

You can find a detailed discussion in:

  • Is Chrome installation needed or only chromedriver when using Selenium?

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
FilesGoogleChromeApplication" 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!

Reason

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:

C:UsersUSERNAMEAppDataLocalGoogle

But since the newer iteration(s) (v85 and above), the default installation path is:

C:Program FilesGoogle

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.

Possible Fixes

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.

I found that the path of chrome.driver in nightwatch web was wrong (Maybe it is just a demo)
I use below code to start my test if you has installed the chromedrive with command npm install chromedriver --save-dev:
In Windows:

 "selenium": {
    "start_process": true,
    "server_path": "./bin/selenium-server-standalone-3.141.59.jar",
    "log_path": "",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "node_modules/chromedriver/lib/chromedriver/chromedriver.exe"
    }
  }

In MacOSX:

"selenium": {
    "start_process": true,
    "server_path": "./bin/selenium-server-standalone-3.141.59.jar",
    "log_path": "",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "node_modules/chromedriver/lib/chromedriver/chromedriver"
    }
  }

Labrador retriever puppy walking on green grass

Sometimes, we want to fix WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome.

In this article, we’ll look at how to fix WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome.

How to fix WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome?

To fix WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome, we set the path of the Chrome binary.

For instance, we write

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = "C:\Program Files\Chrome\chrome64_55.0.2883.75\chrome.exe"
driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:pathtochromedriver.exe')
driver.get('http://example.com/')
driver.quit()

to set create an Options object.

Then we set options.binary_location to the path of the Chrome binary.

And then we set the executable_path to the path of the Chrome driver.

Then we call get to open a page at the URL and call quit to exit.

Conclusion

To fix WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome, we set the path of the Chrome binary.

Web developer specializing in React, Vue, and front end development.

View Archive

The below error occurs when Selenium can’t find the latest Chrome driver on the system (Mostly the Windows agents to run the Selenium UI TestCases)

"OpenQA.Selenium.WebDriverException : unknown error: cannot find Chrome binary"

Solution : This can be explicitly solved by doing any of the below options

  • Hardcode the Chrome driver path on your script (or)
  • Install the Chrome driver explicitly

This issue generally occurs when Selenium is not able to find Chrome driver version and also due to the missing path variable for Chrome.exe (Since Chrome is installed into “C:Program FilesGoogleChromeApplication” this issue may occur

Tags: Azure DevOps IssuesSelenium

You may also like…

Понравилась статья? Поделить с друзьями:
  • Sea of thieves ошибка leekbeard
  • Select at least two edge loops ошибка
  • Seiko lp 1030 ошибка e en 2031
  • Segway ninebot es2 ошибка 15
  • Segnetics pixel ошибка обрыв ремня