Selenium ChromeDriver无法识别新编译的Headless Chromium(Python) [英] Selenium ChromeDriver does not recognize newly compiled Headless Chromium (Python)

查看:261
本文介绍了Selenium ChromeDriver无法识别新编译的Headless Chromium(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将新的(2016) headless 版本的Chromium与Selenium / ChromeDriver一起使用(过去,我将Firefox与xfvb一起使用,但这有望做得更好)。

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).

我根据发现此处,然后我使用以下代码通过Selenium启动它:

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)

相同的代码适用于标准铬(如果我删除 binary.location 选项)

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

但是,出现以下错误:

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)

显然,无头铬二进制文件是使用ChromeDriver无法识别的版本ID编译的。

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

环境:


  • 编译:Ubuntu 16.04服务器

  • 硒执行:Linux Mint 18.1

推荐答案

ChromeHeadless被识别由chromedriver发行,因为此补丁(发布消息后创建),即仅适用于chromedriver 2.29(于2017年4月发布)。确保PATH中有此chromedriver可执行文件,并且Selenium正在选择它,而不是您可能拥有的任何其他chromedriver。

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.

另外,请注意-根据无头Chrome文档-您需要再传递两个标志:

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')

对于无头Chrome的预构建二进制文件-该选项自Chrome 57开始可用,因此,当前通过官方Google存储库发布的所有版本(即稳定的Chrome 58和不稳定的Chrome 59)都支持该版本。它是 Chrome 59 的亮点,因此请期待一些粗糙的边缘,直到功能稳定为止。

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.

这篇关于Selenium ChromeDriver无法识别新编译的Headless Chromium(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆