How do I disable Firefox logging in Selenium using Geckodriver?

与世无争的帅哥 提交于 2019-12-04 00:17:27

To not see the logs in the console you can use the following:

System.setProperty("webdriver.gecko.driver","src/main/resources/drivers/geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");

return new FirefoxDriver();

You can define the desired logging level over command line in geckodriver.exe.

geckodriver.exe -help    
USAGE:
    geckodriver.exe [FLAGS] [OPTIONS]   
...
OPTIONS:
        --log <LEVEL>
            Set Gecko log level [values: fatal, error, warn, info, config,
            debug, trace]

If you use geckodriver from selenium, you have two option:

  • Start geckodriver.exe separately with custom arguments, and use it from selenium over RemoteWebDriver
  • Create a custom wrapper, to add extra parameters to geckodriver.exe

Example geckodriver wrapper bat file (for windows):

@ECHO OFF
ECHO Starting geckodriver: %0 %*
.\GeckoDriver\geckodriver.exe --log fatal %* > NUL 2>&1

In java you can define the geckodriver executable path, over webdriver.gecko.driver system property:

System.setProperty("webdriver.gecko.driver", "c:/selenium/geckodriver/gdrvwrapper.bat");
Akash

Just do this

System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
driver = new FirefoxDriver();

This is the linux version for @voji answer above. Note as I said above in the comment. I don't believe the --log fatal does anything, at least not on linux. However the redirect to NULL works well enough for me

"webdriver.gecko.driver": "/path-to-driver/geckodriver.sh

filename: geckodriver.sh (executable)

#! /bin/bash
echo " ARGS: " $@
geckodriver --log fatal "$@" > /dev/null 2>&1

For selenium 3.14.0 , this is working

System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
Purusothaman S
import org.openqa.selenium.firefox.FirefoxDriver
System.setProperty(
  "webdriver.gecko.driver",
  "C:\Users\geckodriver-v0.22.0-win64\geckodriver.exe"
)
System.setProperty(
  FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,
  "true"
)
System.setProperty(
  FirefoxDriver.SystemProperty.BROWSER_LOGFILE,
  "d:\eclipse\scala_log.txt"
)
  GeckoDriverService gecko = new GeckoDriverService(new File("c:/selenium/geckodriver.exe"), 4444, ImmutableList.of("--log=fatal"), ImmutableMap.of());
  gecko.sendOutputTo(new FileOutputStream("gecko_log.txt"));
  gecko.start();

  FirefoxOptions opts = new FirefoxOptions().setLogLevel(Level.OFF);
  DesiredCapabilities capabilities = opts.addTo(DesiredCapabilities.firefox());
  capabilities.setCapability("marionette", true);
  driver = new FirefoxDriver(gecko, capabilities);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!