Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium ChromeDriver does not recognize newly compiled Headless Chromium (Python)

I am trying to use the new (2016) headless version of Chromium with Selenium/ChromeDriver (In the past, I used Firefox with xfvb but this promises to be much better).

I have compiled a headless version of Chromium from sources (I did not find any pre-built binaries) based on the instructions I found here and then I used the following code to launch it through Selenium:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

l_option = Options()
l_option.add_argument('headless')
l_option.add_argument('disable-notifications')
l_option.binary_location = '/home/fi11222/Headless_Chromium/headless_shell'
l_driver = webdriver.Chrome(chrome_options=l_option)

The same code works with the standard chromium (if I remove the binary.location option)

As is, however, I get the following error:

selenium.common.exceptions.WebDriverException: Message: unknown error: unrecognized Chrome version: HeadlessChrome/59.0.3032.0
  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 4.4.0-53-generic x86_64)

Apparently, the headless chromium binary is compiled with a version ID that ChromeDriver does not recognize. Help !!

Environment:

  • Compilation: Ubuntu 16.04 server
  • Selenium execution: Linux Mint 18.1
like image 384
fi11222 Avatar asked Mar 05 '17 10:03

fi11222


People also ask

How do I run ChromeDriver in headless mode?

Mastering XPath and CSS Selector for Selenium Post version 59, Chrome supports headless execution. ChromeOptions class is utilized to modify the default characteristics of the browser. The addArguments method of the ChromeOptions class is used for headless execution and headless is passed as a parameter to that method.

Does ChromeDriver support Chromium?

Of course ChromeDriver requires Chrome or Chromium. As per ChromeDriver - WebDriver for Chrome ChromeDriver is a separate executable that WebDriver uses to control Chrome.


1 Answers

ChromeHeadless is recognized by chromedriver since this patch (created after you have post your message), which is only available since chromedriver 2.29 (released in April 2017). Make sure that you have this chromedriver executable available in PATH and that Selenium is picking it instead of any other chromedriver you might have available.

Also, please note that - according to headless Chrome documentation - you need to pass two more flags:

l_option.add_argument('remote-debugging-port=9222')
l_option.add_argument('disable-gpu')

As for pre-built binaries of headless Chrome - that option is available since Chrome 57, so it is supported by all versions currently distributed through official Google repository (i.e. stable Chrome 58 and unstable Chrome 59). It is highlight of Chrome 59, so expect some rough edges until feature is stabilized.

like image 168
Mirek Długosz Avatar answered Sep 20 '22 06:09

Mirek Długosz