1

I just uninstalled Chrome because it was acting strange (fixed now) and after this Selenium in Python is not able to identify the Chrome driver binary, which is extremely strange because it should be completely unaffected and it is in a different location and a different version from the chrome I use on my desktop, code is as follows and has worked for years now.

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--load-extension='+exension_path)
driver = webdriver.Chrome(executable_path=chrome_driver_folder,options=chrome_options)

Anyone has any idea what on earth is going on? I get the follow error:

WebDriverException: Message: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
no nein
  • 631
  • 3
  • 10
  • 27

3 Answers3

5

This error message...

WebDriverException: Message: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.

Your main issue is the incompatibility between the version of the binaries you are using as follows:

  • You are using chromedriver=2.40
  • Release Notes of chromedriver=2.40 clearly mentions the following :

Supports Chrome v66-68

  • As you have uninstalled Chrome and reinstalled presumably you are using the latest chrome=85.0
  • Release Notes of ChromeDriver v85.0 clearly mentions the following :

Supports Chrome version 85

So there is a clear mismatch between ChromeDriver v2.40 and the Chrome Browser v85.0


Solution

Ensure that:

  • Selenium is upgraded to current released Version 3.141.59.
  • ChromeDriver is updated to current ChromeDriver v85.0 level.
  • Chrome is updated to current Chrome Version 85.0 level. (as per ChromeDriver v85.0 release notes)
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Is there anyway to download the old chrome browser for v66-68? I have a ton of scripts that is running off that version of chrome and would greatly prefer not to muddle this too much – no nein Sep 18 '20 at 13:34
  • @nonein Tough call, even if are able to install any older version of chrome updater will update it in a short while. – undetected Selenium Sep 18 '20 at 13:37
  • Yeah but thats what I dont get because the other chrome I had was working fine? Was that because I never updated it? Would I not be able to point the driver towards a chrome version that was different? – no nein Sep 18 '20 at 18:26
  • @nonein You are right, presumably the Chrome wasn't updated manually or the updater was modified. You need to match [ChromeDriver-Chrome versions](https://stackoverflow.com/questions/50692358/how-to-work-with-a-specific-version-of-chromedriver-while-chrome-browser-gets-up/50697221#50697221). Check [this](https://stackoverflow.com/questions/48547360/selenium-for-chromedriver-and-chrome-browser-and-the-log-message-only-local-con/48551748#48551748) and [this](https://stackoverflow.com/questions/49796818/chromedriver-not-working-on-raspberry-pi-for-use-with-chromium-and-selenium/49799791#49799791) – undetected Selenium Sep 18 '20 at 19:35
  • additional question in regards to the above, my laptop runs Chrome 85 as well and can use the "old" webdriver, additionally, the old webdriver executes mouse movements MUCH faster than the new driver, factor 10x or so, is there any reason why the driver can run on one computer but not the other even though they use the same version of Chrome? – no nein Oct 05 '20 at 19:20
  • @nonein Let us discuss this in [Selenium Chat Room](https://chat.stackoverflow.com/rooms/223360/selenium) – undetected Selenium Oct 20 '20 at 14:13
1

Automatically get the chrome binary path depending upon your OS:

This function checks the current operating system using platform.system() and returns the expected path to the Chrome binary.

It handles default Chrome locations on:

  • Darwin (MacOS)
  • Linux
  • Windows

If the OS is not one of the above, an exception is raised.

The return value can be used to set the binary_location in Selenium's ChromeOptions.

import platform

def get_chrome_binary():
  # Check the operating system and set the Chrome binary path accordingly
  if platform.system() == "Darwin":  # macOS
      binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
  elif platform.system() == "Linux":  # Linux-based system (e.g., Ubuntu Docker container)
      binary_location = '/usr/bin/google-chrome'
  elif platform.system() == "Windows":  # Windows
      # Provide the path to the Chrome executable on Windows
      binary_location = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'  # Adjust the path as needed
  else:
      raise Exception("Unsupported operating system")  # You can handle other OSes based on your requirements
  
  return binary_location
0

In order to have a clean code and to stop track the chrome path/version, I recommend to you to use webdriver_manager

Install it

pip install webdriver_manager

and use it like this

from webdriver_manager.chrome import ChromeDriverManager

options = webdriver.ChromeOptions()
chrome_options.add_argument('--load-extension='+exension_path)
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=options)

but if don't want to use it here is the code for local browser

chrome_options = Options()  
chrome_options.add_argument('--load-extension='+exension_path)
chrome_options.binary_location = 'YOUR_PATH'  
driver = webdriver.Chrome(executable_path=os.path.abspath(“chromedriver"),   chrome_options=chrome_options)

but I totally recommend using the first version.

Alin Stelian
  • 861
  • 1
  • 6
  • 16
  • the Options(), what library is that from? If I exclude the chrome_options = Options() then I still get the following error: WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home – no nein Sep 18 '20 at 12:50
  • Selenium Options - from selenium.webdriver.chrome.options import Options – Alin Stelian Sep 18 '20 at 12:58