Selenium: Trying to get Firefox console logs results in "WebDriverError: HTTP method not allowed"

Con*_*roß 3 firefox selenium node.js selenium-webdriver geckodriver

I'm trying to capture console errors in my selenium tests (node environment with selenium-webdriver 4.0.0-alpha.5 and the latest geckodriver and chromedriver). I've set up one driver for Firefox and another one for Chrome like this:

const chrome = require('selenium-webdriver/chrome');
const firefox = require('selenium-webdriver/firefox');
const webdriver = require('selenium-webdriver');
const { Builder, By, Capabilities, until } = webdriver;

let loggingPref = new webdriver.logging.Preferences();
loggingPref.setLevel( 'browser', webdriver.logging.Level.SEVERE );

let driver_fx = await new Builder()
  .withCapabilities(
    Capabilities.firefox()
    .set("acceptInsecureCerts", true)
  )
  .setLoggingPrefs( loggingPref )
  .build();

let driver_chr = await new Builder()
  .forBrowser('chrome')
  .setLoggingPrefs( loggingPref )
  .build();
Run Code Online (Sandbox Code Playgroud)

This is the function that should get the error logs:

const getConsoleErrors = (driver) => {
  return driver.manage().logs().get('browser').then((logs) => {
    return logs.map(( log ) => log.message );
  });
}
Run Code Online (Sandbox Code Playgroud)

With the chrome driver, this works as intended:

await driver.get(devUrl);

let errors = await getConsoleErrors(driver_chr);
console.log(errors);
// output:
// [ 'https://mylocaldevserver/with/path 465:61 Uncaught TypeError: Cannot read property \'textContent\' of null' ]
Run Code Online (Sandbox Code Playgroud)

However, when passing driver_fx to the function instead, this results in the following exception:

WebDriverError: HTTP method not allowed
at parseHttpResponse (***\node_modules\selenium-webdriver\lib\http.js:580:11)
at Executor.execute (***\node_modules\selenium-webdriver\lib\http.js:489:26)
at process._tickCallback (internal/process/next_tick.js:68:7)

Is this a bug in selenium or geckodriver, or is it the way I construct the Firefox driver differently (which I need to do for it to ignore the certificate of my local dev server)?

atb*_*ker 6

对于未来的 googlers,不幸的log('browser')是不在 W3C 规范中,因此geckodriver团队似乎正在拖延它。截至今天(2020 年 2 月 17 日),还没有针对它的官方“修复”。

您很可能必须使用以下解决方法:https : //github.com/mozilla/geckodriver/issues/284#issuecomment-477677764

在此处查找更多信息:https : //github.com/mozilla/geckodriver/issues/284