unknown error: cannot get automation extension

unknown error: cannot get automation extension

无法在 headless 模式下进行 运行 测试;它似乎不是代码片段的问题,因为我以不同的方式尝试它并且结果是相同的。

  caps = Selenium::WebDriver::Remote::Capabilities.chrome(chromeOptions: { binary: "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome",
                                                                           args: [ "--headless" ]})
  @driver = Selenium::WebDriver.for :chrome, desired_capabilities: caps

错误

unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
    (Session info: headless chrome=59.0.3071.115)
    (Driver info: chromedriver=2.31.488774 (7e15618d1bf16df8bf0ecf2914ed1964a387ba0b),platform=Mac OS X 10.12.3 x86_64) (Selenium::WebDriver::Error::UnknownError)

Chrome browser: 59.0.3071.115 (latest)

Chrome driver: chromedriver=2.31.488774 (latest)

Language used: Ruby

这是 chrome 驱动程序中的一个已知问题。如github

中所述

This is a long standing issue with Chromedriver. The window resizing doesn't work with the chromedriver and the community is silent on this bug fix. If the resizing is not critical for your tests, I would suggest you avoid the manage() method altogether and use a workaround of having your browser window always maximized using the ChromeOptions object at the launch of your chromedriver instantiation.

虽然不是每个人都会这样,但问题仍然存在。它主要通过将 chrome 或 chrome 驱动程序更新到最新版本来解决(仍然对大多数人不起作用)

所以最好不要在 chrome 上使用最大化或调整 activity 的大小。但是,如果您愿意,可以使用 ChromeDriver[= 建议的 ChromeOptions 15=]

ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");