Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac
Asked Answered
F

12

54

Trying to get selenium to work with Python 3 for web scraping purposes:

from selenium import webdriver
chrome_path = r"/Library/Frameworks/Python.framework/Versions/3.6/bin/chromedriver"
driver = webdriver.Chrome(chrome_path)

I get the following error message:

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

A similar question was addressed here, but what is baffling to me is that Chrome is already installed on my system. The other asker apparently didn't have it on their computer. I'm running latest version of Mac OS.

Forman answered 3/9, 2017 at 19:11 Comment(4)
Which version of chrome are you using ? Please attach a screenshot of the version with your questionAncestral
Version 60.0.3112.113Forman
Which path is your chrome installed on?Ancestral
File is stored at: /Users/alex/DesktopForman
A
66

The issue is that chromedriver also needs to know where chrome is. In your case it is at a non-default path. So you need to specify the complete path to the Google Chrome binary.

options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
chrome_driver_binary = "/usr/local/bin/chromedriver"
driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)

Above code is what you should use

Ancestral answered 3/9, 2017 at 20:24 Comment(3)
Do not miss that the path does not end with ..../chrome.app The path should include contents/macos/Planimetry
If I code in Google Colab, How to get the binary location?Jackscrew
good day dear Tarun - many thanks: well what can i do if i am facing this issue in google-colab. Well that is a bit special i think: Can i do a workaround there too!? - see my thread here: #76401953 - look forward to hear from you. RegardsEaton
B
9

I have met this annoying problem when I am lerning selenium. This is my solution: (MacOS 10.13.4)

  1. uninstall my chrome
  2. use homebrew to install chromedriver: brew cask install chromedriver
  3. use homebrew to install chrome: brew cask install google-chrome

Thanks to homebrew now chrome and chromedriver are installed in the same folder and this problem will be automatically solved.

Boykins answered 19/5, 2018 at 19:24 Comment(2)
In 2021, just brew install google-chrome will do.Lip
goof day dear joseph - many thanks: well what can i do if i am facing this issue in google-colab. Can i do a workaround there too!? - see my thread here: #76401953 - look forward to hear from you. RegardsEaton
C
7

If anyone is getting the same error on a linux machine, then you are missing google chrome installation as one of the steps needed for chrome driver to work.

Follow this link to install Google chrome on Linux.

Now, check code

driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=chrome_options, service_args=['--verbose', '--log-path=/tmp/chromedriver.log'])

For me it worked.

Cloverleaf answered 29/9, 2018 at 16:47 Comment(0)
H
7

It is important on Win to set the name of chrome.exe otherwise it fail to create a process (see below):

  from selenium import webdriver
  from webdriver_manager.chrome import ChromeDriverManager

  options = webdriver.ChromeOptions()
  options.binary_location = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
  chrome_driver_binary = r"C:/Users/Max/.wdm/chromedriver/75.0.3770.8/win32/chromedriver.exe"
  driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
  driver.get('http://web.whatsapp.com')

selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.

For Firefox (download driver https://github.com/mozilla/geckodriver/releases):

  options = webdriver.FirefoxOptions()
  #options.add_argument('-headless')
  #options.binary_location = r"C:\maxbook\maxboxpython\geckodriver-v0.24.0-win64\geckodriver.exe"
  options.binary_location = r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
  firefox_driver_binary = r"C:\maxbook\maxboxpython\geckodriver-v0.24.0-win64\\"
  driver = webdriver.Firefox(firefox_driver_binary, options=options)
Housefather answered 12/6, 2019 at 15:3 Comment(3)
good evening dear Max - well i wonder how to get this fix included in google-colab!? It is important for me to get a solution in google colab. How to do that!?Eaton
in colab you can use download as well with wget (with ! at the begin): !wget github.com/maxkleiner/maXbox4/releases/download/V4.2.4.80/… #!sudo apt-get install unzip !unzip maxbox4.zip !ls -lHousefather
dear Max - many thanks for the answer and all your hints - i try to get the things up and running - see here: #76401953 - but untill now - still struggle with all my approaches - look forward to hear from yiou. RegardsEaton
A
4

In my case, I install the Chrome browser then it's not throwing an error.

Aras answered 16/2, 2021 at 12:12 Comment(2)
Hi there - many thanks for the hint. I am trying to do soEaton
@what command did you use to install the browser?Rain
K
3
options = webdriver.ChromeOptions()
options.binary_location = r"<YOUR_CHROME_PATH>\chrome.exe"
chrome_driver_path = r"<PATH_TO_CHROME_DRIVER>\chromedriver.exe>"

browser = webdriver.Chrome(chrome_driver_path, chrome_options=options)
Karolyn answered 28/3, 2018 at 14:55 Comment(2)
More explanation would be helpful for the OP.Emulous
@Emulous Mar see bellow please.Karolyn
S
2

If your chromedriver is located within /Library/Frameworks/Python.framework/Versions/3.6/bin/ directory the following code block should be working for you:

from selenium import webdriver

chrome_path = r'/Library/Frameworks/Python.framework/Versions/3.6/bin/chromedriver'
driver = webdriver.Chrome(executable_path=chrome_path)
driver.get('https://www.google.co.in')
Stinker answered 5/9, 2017 at 11:16 Comment(2)
well dear undeteched Selenium - many thanks - i am trying to get this solution working for me.Eaton
hello dear undetected Selenium - first of all many many thanks for your ciontinued help in all that things: dear u. Selenium: again many thanks for the answer and all your hints - i try to get the things up and running - see here: #76401953 - but untill now - still struggle with all my approaches - look forward to hear from yiou. RegardsEaton
A
1

all you need is download latest version of chrome and chromedriver and install it

Animism answered 11/5, 2021 at 14:46 Comment(0)
B
0

This article gives the full breakdown on what is happening. Installing the latest web driver should fix the problem rather than changing the code.

Basically version 85 of chrome was installed in a different location, however this only affected new installations so it wasn't noticeable for most people.

The latest web driver understands about the new location so getting an updated driver is the easiest solution - that is of course unless you specifically need to test an older version.

Location of drivers.

Boxing answered 5/5, 2021 at 21:43 Comment(0)
O
0

I recently solved this issue by simply downloading the Chrome Browser. Download it and to download latest version of chrome driver by using this code

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
Oestriol answered 30/12, 2022 at 23:51 Comment(0)
S
0

Create file main.py has content

from selenium import webdriver

options = webdriver.ChromeOptions()
options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
chrome_driver_binary = r"C:/Users/firerose/Downloads/chromedriver_win32/chromedriver.exe"
driver = webdriver.Chrome(chrome_driver_binary, options=options)
driver.get('https://golangnow.com')

Notice: New keyword is options .

Releated links

Stedt answered 11/5, 2023 at 15:6 Comment(0)
A
-1

For mac: Note space between Chrome and .app

options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Google Chrome .app/Contents/MacOS/Google Chrome"
chrome_driver_binary = "/usr/local/bin/chromedriver"
driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
Always answered 9/1, 2023 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.