seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
5.36k stars 979 forks source link

selenium.common.exceptions.WebDriverException: Message: unknown error: c annot find Chrome binary #206

Closed ithjz closed 6 years ago

ithjz commented 6 years ago
        exception_class = ElementNotVisibleException
    elif status in ErrorCode.INVALID_ELEMENT_STATE:
        exception_class = InvalidElementStateException
    elif status in ErrorCode.INVALID_SELECTOR \
            or status in ErrorCode.INVALID_XPATH_SELECTOR \
            or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
        exception_class = InvalidSelectorException
    elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
        exception_class = ElementNotSelectableException
    elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
        exception_class = ElementNotInteractableException
    elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
        exception_class = InvalidCookieDomainException
    elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
        exception_class = UnableToSetCookieException
    elif status in ErrorCode.TIMEOUT:
        exception_class = TimeoutException
    elif status in ErrorCode.SCRIPT_TIMEOUT:
        exception_class = TimeoutException
    elif status in ErrorCode.UNKNOWN_ERROR:
        exception_class = WebDriverException
    elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
        exception_class = UnexpectedAlertPresentException
    elif status in ErrorCode.NO_ALERT_OPEN:
        exception_class = NoAlertPresentException
    elif status in ErrorCode.IME_NOT_AVAILABLE:
        exception_class = ImeNotAvailableException
    elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
        exception_class = ImeActivationFailedException
    elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
        exception_class = MoveTargetOutOfBoundsException
    elif status in ErrorCode.JAVASCRIPT_ERROR:
        exception_class = JavascriptException
    elif status in ErrorCode.SESSION_NOT_CREATED:
        exception_class = SessionNotCreatedException
    elif status in ErrorCode.INVALID_ARGUMENT:
        exception_class = InvalidArgumentException
    elif status in ErrorCode.NO_SUCH_COOKIE:
        exception_class = NoSuchCookieException
    elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
        exception_class = ScreenshotException
    elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
        exception_class = ElementClickInterceptedException
    elif status in ErrorCode.INSECURE_CERTIFICATE:
        exception_class = InsecureCertificateException
    elif status in ErrorCode.INVALID_COORDINATES:
        exception_class = InvalidCoordinatesException
    elif status in ErrorCode.INVALID_SESSION_ID:
        exception_class = InvalidSessionIdException
    elif status in ErrorCode.UNKNOWN_METHOD:
        exception_class = UnknownMethodException
    else:
        exception_class = WebDriverException
    if value == '' or value is None:
        value = response['value']
    if isinstance(value, basestring):
        if exception_class == ErrorInResponseException:
            raise exception_class(response, value)
        raise exception_class(value)
    if message == "" and 'message' in value:
        message = value['message']

    screen = None
    if 'screen' in value:
        screen = value['screen']

    stacktrace = None
    if 'stackTrace' in value and value['stackTrace']:
        stacktrace = []
        try:
            for frame in value['stackTrace']:
                line = self._value_or_default(frame, 'lineNumber', '')
                file = self._value_or_default(frame, 'fileName', '<anonymous

') if line: file = "%s:%s" % (file, line) meth = self._value_or_default(frame, 'methodName', '<anonymo us>') if 'className' in frame: meth = "%s.%s" % (frame['className'], meth) msg = " at %s (%s)" msg = msg % (meth, file) stacktrace.append(msg) except TypeError: pass if exception_class == ErrorInResponseException: raise exception_class(response, message) elif exception_class == UnexpectedAlertPresentException: alert_text = None if 'data' in value: alert_text = value['data'].get('text') elif 'alert' in value: alert_text = value['alert'].get('text') raise exception_class(message, screen, stacktrace, alert_text) raise exception_class(message, screen, stacktrace) E selenium.common.exceptions.WebDriverException: Message: unknown error: c annot find Chrome binary E (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3e b905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64)

e:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandle r.py:242: WebDriverException

During handling of the above exception, another exception occurred: ..\seleniumbase\fixtures\base_case.py:3085: in setUp switch_to=True) ..\seleniumbase\fixtures\base_case.py:2496: in get_new_driver proxy_string=proxy_string) ..\seleniumbase\core\browser_launcher.py:161: in get_driver return get_local_driver(browser_name, headless, proxy_string) ..\seleniumbase\core\browser_launcher.py:342: in get_local_driver return webdriver.Chrome(executable_path=LOCAL_CHROMEDRIVER) e:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.p y:75: in init desired_capabilities=desired_capabilities) e:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.p y:156: in init self.start_session(capabilities, browser_profile) e:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.p y:251: in start_session response = self.execute(Command.NEW_SESSION, parameters) e:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.p y:320: in execute self.error_handler.check_response(response)


self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x00000000 04F34EF0> response = {'sessionId': '7f07e0ad8bb1dbd36eb27c3283d5a58d', 'status': 13, 'valu e': {'message': 'unknown error: cannot find Chrom...r info: chromedriver=2.40.56 5498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64)'}}

def check_response(self, response):
    """
        Checks that a JSON response from the WebDriver does not have an erro

r.

        :Args:
         - response - The JSON response from the WebDriver server as a dicti

onary object.

        :Raises: If the response contains an error message.
        """
    status = response.get('status', None)
    if status is None or status == ErrorCode.SUCCESS:
        return
    value = None
    message = response.get("message", "")
    screen = response.get("screen", "")
    stacktrace = None
    if isinstance(status, int):
        value_json = response.get('value', None)
        if value_json and isinstance(value_json, basestring):
            import json
            try:
                value = json.loads(value_json)
                if len(value.keys()) == 1:
                    value = value['value']
                status = value.get('error', None)
                if status is None:
                    status = value["status"]
                    message = value["value"]
                    if not isinstance(message, basestring):
                        value = message
                        message = message.get('message')
                else:
                    message = value.get('message', None)
            except ValueError:
                pass

    exception_class = ErrorInResponseException
    if status in ErrorCode.NO_SUCH_ELEMENT:
        exception_class = NoSuchElementException
    elif status in ErrorCode.NO_SUCH_FRAME:
        exception_class = NoSuchFrameException
    elif status in ErrorCode.NO_SUCH_WINDOW:
        exception_class = NoSuchWindowException
    elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
        exception_class = StaleElementReferenceException
    elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
        exception_class = ElementNotVisibleException
    elif status in ErrorCode.INVALID_ELEMENT_STATE:
        exception_class = InvalidElementStateException
    elif status in ErrorCode.INVALID_SELECTOR \
            or status in ErrorCode.INVALID_XPATH_SELECTOR \
            or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
        exception_class = InvalidSelectorException
    elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
        exception_class = ElementNotSelectableException
    elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
        exception_class = ElementNotInteractableException
    elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
        exception_class = InvalidCookieDomainException
    elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
        exception_class = UnableToSetCookieException
    elif status in ErrorCode.TIMEOUT:
        exception_class = TimeoutException
    elif status in ErrorCode.SCRIPT_TIMEOUT:
        exception_class = TimeoutException
    elif status in ErrorCode.UNKNOWN_ERROR:
        exception_class = WebDriverException
    elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
        exception_class = UnexpectedAlertPresentException
    elif status in ErrorCode.NO_ALERT_OPEN:
        exception_class = NoAlertPresentException
    elif status in ErrorCode.IME_NOT_AVAILABLE:
        exception_class = ImeNotAvailableException
    elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
        exception_class = ImeActivationFailedException
    elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
        exception_class = MoveTargetOutOfBoundsException
    elif status in ErrorCode.JAVASCRIPT_ERROR:
        exception_class = JavascriptException
    elif status in ErrorCode.SESSION_NOT_CREATED:
        exception_class = SessionNotCreatedException
    elif status in ErrorCode.INVALID_ARGUMENT:
        exception_class = InvalidArgumentException
    elif status in ErrorCode.NO_SUCH_COOKIE:
        exception_class = NoSuchCookieException
    elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
        exception_class = ScreenshotException
    elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
        exception_class = ElementClickInterceptedException
    elif status in ErrorCode.INSECURE_CERTIFICATE:
        exception_class = InsecureCertificateException
    elif status in ErrorCode.INVALID_COORDINATES:
        exception_class = InvalidCoordinatesException
    elif status in ErrorCode.INVALID_SESSION_ID:
        exception_class = InvalidSessionIdException
    elif status in ErrorCode.UNKNOWN_METHOD:
        exception_class = UnknownMethodException
    else:
        exception_class = WebDriverException
    if value == '' or value is None:
        value = response['value']
    if isinstance(value, basestring):
        if exception_class == ErrorInResponseException:
            raise exception_class(response, value)
        raise exception_class(value)
    if message == "" and 'message' in value:
        message = value['message']

    screen = None
    if 'screen' in value:
        screen = value['screen']

    stacktrace = None
    if 'stackTrace' in value and value['stackTrace']:
        stacktrace = []
        try:
            for frame in value['stackTrace']:
                line = self._value_or_default(frame, 'lineNumber', '')
                file = self._value_or_default(frame, 'fileName', '<anonymous

') if line: file = "%s:%s" % (file, line) meth = self._value_or_default(frame, 'methodName', '<anonymo us>') if 'className' in frame: meth = "%s.%s" % (frame['className'], meth) msg = " at %s (%s)" msg = msg % (meth, file) stacktrace.append(msg) except TypeError: pass if exception_class == ErrorInResponseException: raise exception_class(response, message) elif exception_class == UnexpectedAlertPresentException: alert_text = None if 'data' in value: alert_text = value['data'].get('text') elif 'alert' in value: alert_text = value['alert'].get('text') raise exception_class(message, screen, stacktrace, alert_text) raise exception_class(message, screen, stacktrace) E selenium.common.exceptions.WebDriverException: Message: unknown error: c annot find Chrome binary E (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3e b905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64)

e:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandle r.py:242: WebDriverException ============================== warnings summary =============================== source:1067: DeprecationWarning: invalid escape sequence \S source:1168: DeprecationWarning: invalid escape sequence \S source:1289: DeprecationWarning: invalid escape sequence \S source:131: DeprecationWarning: invalid escape sequence \d source:141: DeprecationWarning: invalid escape sequence \d source:358: DeprecationWarning: invalid escape sequence _ source:374: DeprecationWarning: invalid escape sequence _ source:625: DeprecationWarning: invalid escape sequence * source:649: DeprecationWarning: invalid escape sequence *

-- Docs: https://docs.pytest.org/en/latest/warnings.html ==================== 1 failed, 9 warnings in 8.33 seconds =====================

E:\users\administrator\eclipse-workspace2\SeleniumBase-master\examples>

mdmintz commented 6 years ago

Hi @ithjz Have you tried using seleniumbase install chromedriver ? It doesn't seem to be on your path.

mdmintz commented 6 years ago

Additionally, get the new seleniumbase version 1.15.8 to take care of those deprecation warnings you see, which are related to the version of python used. Also, add a "--upgrade" to your pip install to make sure you have the latest versions of python packages being used: pip install -r requirements.txt --upgrade

mdmintz commented 6 years ago

@ithjz Now, v1.15.10 should take care of the remaining DeprecationWarnings you saw (https://github.com/seleniumbase/SeleniumBase/pull/209/files), which updated methods that use regular expressions to pass raw strings. Use pip install -U seleniumbase --no-cache-dir to reinstall from pypi, (Or pip install -U -i https://pypi.anaconda.org/seleniumbase/simple seleniumbase if you're using Anaconda Cloud). Then get chromedriver into your seleniumbase drivers folder with seleniumbase install chromedriver.

mdmintz commented 6 years ago

I haven't heard back in 4 days, so I'll assume this issue is resolved. Please update to the latest version of seleniumbase if you haven't already.

bschollnick commented 4 years ago

(In case someone else runs into this.) I was seeing the same issue under Windows Server.

seleniumbase install chromedriver

Worked fine, no errors, but seleniumbase would die with "cannot find Chrome Binary".

For some reason, I HAD to use seleniumbase install chromedriver latest.

As soon as I did that, everything worked fine.

bukowa commented 3 years ago
  ** install **

  Usage:
          seleniumbase install [DRIVER_NAME] [OPTIONS]
              (Drivers: chromedriver, geckodriver, edgedriver,
                        iedriver, operadriver)
  Options:
          VERSION         Specify the version.
                          (Default chromedriver version = 2.44)
                          Use "latest" for the latest version.
          -p OR --path    Also copy the driver to /usr/local/bin

It would be cool to specify custom path!

mdmintz commented 3 years ago

@bukowa It can always be copied to another location, but these are the safe paths to use. There could be permissions issues, etc, when using other paths. The only time that the seleniumbase/drivers folder isn't good enough is when using a Selenium Grid - that requires the driver to be on the system path. Otherwise, it's safer to use seleniumbase/drivers because then you could have a different version of the browser driver for different virtual environments. If the system path is used, all users would have to use the same driver.

bukowa commented 1 year ago
(venv) (⎈|N/A:default)➜  tests git:(new2) ✗ seleniumbase install chromedriver latest

*** chromedriver version for download = 107.0.5304.62 (Latest)

Downloading chromedriver_linux64.zip from:
https://chromedriver.storage.googleapis.com/107.0.5304.62/chromedriver_linux64.zip ...
Download Complete!

Extracting ['chromedriver'] from chromedriver_linux64.zip ...
Unzip Complete!

The file [chromedriver] was saved to:
/home/buk/Git/k8s-wp/venv/lib/python3.10/site-packages/seleniumbase/drivers/chromedriver

Making [chromedriver 107.0.5304.62] executable ...
[chromedriver 107.0.5304.62] is now ready for use!
(venv) (⎈|N/A:default)➜  tests git:(new2) ✗ pytest .                                
(Linux uses --headless by default. To override, use --headed / --gui. For Xvfb mode instead, use --xvfb. Or hide this info with --headless, or by calling the new --headless2.)
==================================================================================================================== test session starts =====================================================================================================================
platform linux -- Python 3.10.6, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/buk/Git/k8s-wp/tests
plugins: html-2.0.1, metadata-2.0.4, xdist-3.0.2, forked-1.4.0, rerunfailures-10.2, seleniumbase-4.8.2, ordering-0.6
collected 1 item                                                                                                                                                                                                                                             

basic_test.py

FAILED basic_test.py::MyTestClass::test_basics - selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

I wonder why it still doesn't work out of the box with venv :/

bukowa commented 1 year ago

It works with firefox seleniumbase install geckodriver pytest --headed --browser=firefox

mdmintz commented 1 year ago

@bukowa cannot find Chrome binary means that Chrome wasn't found on your machine. Chrome must be installed separately. (SeleniumBase only downloads the drivers for you.)

bukowa commented 1 year ago

@bukowa cannot find Chrome binary means that Chrome wasn't found on your machine. Chrome must be installed separately. (SeleniumBase only downloads the drivers for you.)

Oh ok thank you

zhiyu1998 commented 1 month ago

I've found a better way to handle the current situation:

  1. Download a relatively new driver, such as:

    https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/118.0.5993.70/win64/chromedriver-win64.zip

  2. Place this driver in path\to\Lib\site-packages\seleniumbase\drivers. It might be a virtual environment, so adjust accordingly

Then it can be run.