Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Chrome installation needed or only chromedriver when using Selenium?

I've tried to search, but haven't found a definitive answer. On Windows Server 2016 WITHOUT Chrome Browser actually installed. I downloaded the correct "chromedriver.exe" and placed it in "D:\Apps\chromedriver.exe". I have added to my environment PATH the full path as "D:\Apps\chromedriver.exe".

When I attempt to start my Windows Service that utilizes the latest Selenium, I get the following error:

Exception occurred: Failed initializing web driver: Message: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)

Question: Do I have to actually install the full-blown browser in addition to the chromedriver, or is this simply just not finding the chromedriver.exe in my Python code (included below for full disclosure):

def __init__(self, username, password, environment='cert'):
    self.username = username
    self.password = password
    self.environment = environment

    # Instantiate a chrome options object so you can set the size and headless preference
    self.chrome_options = Options()

    # Toggle Headless or not
    if HEADLESS_TOGGLE == 1:
        self.chrome_options.add_argument("--headless")

    self.chrome_options.add_argument("--disable-gpu")  # Disables "Lost UI Shared Context GPU Error on Windows"
    self.chrome_options.add_argument('--disable-extensions')  # Disables Extensions
    self.chrome_options.add_argument("--disable-software-rasterizer")  # Disables "Lost UI Shared Context GPU Error on Windows"
    self.chrome_options.add_argument("--window-size=1024x768")
    self.chrome_options.add_argument("--log-level=3")  # Errors Only
    self.chrome_options.add_argument("--incognito")  # Keeps history and logs clear
    self.chrome_options.add_argument("--no-sandbox")
    self.chrome_options.add_argument("--mute_audio")  # No loud surprises!
    self.chrome_options.add_argument("--no-gpu")  # Disables gpu-based errors (headless)

    self.driver = webdriver.Chrome(chrome_options=self.chrome_options)
like image 458
Source Matters Avatar asked Nov 16 '18 01:11

Source Matters


People also ask

Do you need Chrome driver for Selenium?

Why do you need ChromeDriver? The main purpose of the ChromeDriver is to launch Google Chrome. Without that, it is not possible to execute Selenium test scripts in Google Chrome as well as automate any web application. This is the main reason why you need ChromeDriver to run test cases on Google Chrome browser.

Can Selenium run without browser installed?

We can perform Selenium testing without a browser. This is achieved by triggering the execution in a headless mode. The headless execution can decrease the utilization of key resources and is being adopted widely.

Is ChromeDriver installed with Chrome?

ChromeDriver is a standalone server that implements the W3C WebDriver standard. ChromeDriver is available for Chrome on Android and Chrome on Desktop (Mac, Linux, Windows and ChromeOS). You can view the current implementation status of the WebDriver standard here.

How do I add Chrome to Selenium?

Below are the steps to follow while configuring the chrome setup for Selenium. #1) Check the version of the chrome. #3) Download the chromedriver.exe file for the respective OS and copy that .exe file into your local. #4) The path of the chromedriver (C:\webdriver\chromedriver.exe) will be used in our program.


2 Answers

This error message...

Exception occurred: Failed initializing web driver: Message: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)

...implies that the ChromeDriver was unable to find the Chrome binary while trying to initiate a new new Browsing Context i.e. Chrome Browser session.


As per the documentation with in the wiki page of ChromeDriver:

  • ChromeDriver is a standalone server which earlier implemented the WebDriver's wire protocol but slowly and gradually shifting it's implementation as per WebDriver standard.

  • The ChromeDriver consists of three separate pieces.

    • There is the browser itself i.e. chrome
    • The language bindings provided by the Selenium project i.e. the driver
    • An executable downloaded from the Chromium project which acts as a bridge between chrome and the driver which is called chromedriver and we refer to it as the server.
  • In generic scenarios the server expects you to have Chrome installed in the default location for each system:
    • Linux: /usr/bin/google-chrome 1
    • Mac: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
    • Windows XP: %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
    • Windows Vista and newer: C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe

Note: 1: For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.

You can find a detailed discussion on overriding the default Chrome binary location in WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome


Solution

So ideally to execute your tests using ChromeDriver / Chrome combo you need to:

  • Install the full-blown google-chrome browser.
  • Download the compatible version of chromedriver.exe
  • Quick installation of ChromeDriver:
    • Mac users with Homebrew: brew tap homebrew/cask && brew cask install chromedriver
    • Debian based Linux distros: sudo apt-get install chromium-chromedriver
    • Windows users with Chocolatey installed: choco install chromedriver
  • You can find a couple of relevant discussions in:
    • How to work with a specific version of ChromeDriver while Chrome Browser gets updated automatically through Python selenium
    • Selenium for ChromeDriver and Chrome Browser and the log message “Only local connections are allowed”
    • WebDriverException: Message: Service /usr/lib/chromium-browser/chromedriver unexpectedly exited on Raspberry-Pi with ChromeDriver and Selenium

Reference

You can find a detailed discussion in:

  • WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome
like image 189
undetected Selenium Avatar answered Oct 10 '22 07:10

undetected Selenium


Users provided relevant link to confirm that, "YES" a full Chrome installation is needed in addition to the actual chromedriver.

Link: https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver

like image 26
Source Matters Avatar answered Oct 10 '22 05:10

Source Matters