no nein
no nein

Reputation: 711

Selenium driven ChromeDriver can't find Chrome binary

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)

Upvotes: 1

Views: 21347

Answers (3)

Sudhanshu Kumar
Sudhanshu Kumar

Reputation: 11

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

Upvotes: 1

undetected Selenium
undetected Selenium

Reputation: 193058

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.

Upvotes: 5

Alin Stelian
Alin Stelian

Reputation: 887

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.

Upvotes: 0

Related Questions