Home>

I installed chromedriver from homebrew and wrote the code as below, but I got an error at browser = webdriver.Chrome (). What are the possible causes? Thank you.

! pip install selenium

! pip install beautifulsoup4

from selenium import webdriver

import time
import pandas as bd

USER = "test_user"
PASS = "test_pw"

browser = webdriver.Chrome ()
browser.implicitly_wait (5) **

#Error location

WebDriverException Traceback (most recent call last)
in
---->1 browser = webdriver.Chrome ()
2 browser.implicitly_wait (5)

~/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py ininit(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
74
75 try:
--->76 RemoteWebDriver.init(
77 self,
78 command_executor = ChromeRemoteConnection (

~/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py ininit(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
155 warnings.warn ("Please use FirefoxOptions to set browser profile",
156 DeprecationWarning, stacklevel = 2)
->157 self.start_session (capabilities, browser_profile)
158 self._switch_to = SwitchTo (self)
159 self._mobile = Mobile (self)

~/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py in start_session (self, capabilities, browser_profile)
250 parameters = {"capabilities": w3c_caps,
251 "desiredCapabilities": capabilities}
->252 response = self.execute (Command.NEW_SESSION, parameters)
253 if'sessionId' not in response:
254 response = response ['value']

~/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py in execute (self, driver_command, params)
319 response = self.command_executor.execute (driver_command, params)
320 if response:
->321 self.error_handler.check_response (response)
322 response ['value'] = self._unwrap_value (
323 response.get ('value', None))

~/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py in check_response (self, response)
240 alert_text = value ['alert'] .get ('text')
241 raise exception_class (message, screen, stacktrace, alert_text)
->242 raise exception_class (message, screen, stacktrace)
243
244 def _value_or_default (self, obj, key, default):

WebDriverException: Message: unknown error: cannot find Chrome binary

  • Answer # 1

    It may not be found in chromedirver because Chrome does not exist or is not in the default path.

    First, check if Google Chrome.app exists under the application in the finder.
    At the terminal'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'Type in the box with and'and see if Chrome starts.

    If the above doesn't work, look for Google Chrome.app to find the correct path.
    (Path after Contents is not visible in Finder)

    Once you know the correct path, move it to the default path in the viewfinder if possible.
    If you want to use it as it is, you need to modify binary_location to the correct path with the code below.

    options = webdriver.chrome.options.Options ()
    options.binary_location ='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
    browser = webdriver.Chrome (options = options)