问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/42607084/selenium-chromedriver-does-not-recognize-newly-compiled-headless-chromium-pytho