16

I am using:

  • firefox version 50.1.0
  • geckodriver version 0.11.1
  • selenium-java 3.0.1

I have tried

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("webdriver.log.browser.ignore", true);
profile.setPreference("webdriver.log.driver.ignore", true);
profile.setPreference("webdriver.log.profiler.ignore", true);
FirefoxDriver driver = new FirefoxDriver();

and

LoggingPreferences preferences = new LoggingPreferences();
preferences.enable(LogType.BROWSER, Level.OFF);
preferences.enable(LogType.CLIENT, Level.OFF);
preferences.enable(LogType.DRIVER, Level.OFF);
preferences.enable(LogType.PERFORMANCE, Level.OFF);
preferences.enable(LogType.SERVER, Level.OFF);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.LOGGING_PREFS, preferences);
FirefoxDriver driver = new FirefoxDriver(capabilities);

neither of these methods does anything to stop logging. Here is console output if that helps somehow:

For those wondering, i have log4j 1.2.17 in my pom.xml but have no log4j.properties or log4j.xml and I do not use it at all.


To clarify: when I say logging I mean the console output in IntelliJ IDEA. I am using Java.

maxbfuer
  • 839
  • 2
  • 9
  • 15
  • Why are u using geckodriver ? It's needed for Firefox ? oh ok got it, it's new in selenium 3 – Pascal Heraud Dec 29 '16 at 22:11
  • If I'm not mistaken, Geckodriver is needed for Firefox with selenium 3.0.0 and up – maxbfuer Dec 29 '16 at 22:12
  • Possible duplicate of [How to turn off the Marionette/gecko driver logs in selenium 3](https://stackoverflow.com/questions/41696695/how-to-turn-off-the-marionette-gecko-driver-logs-in-selenium-3) – Suresh Kumar Aug 02 '18 at 04:55

9 Answers9

16

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();
Michael Medina
  • 566
  • 5
  • 5
  • 1
    How would I set the marionette log level to "warn"? – Jonathan Sep 22 '18 at 21:52
  • From https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxDriver.SystemProperty.html#BROWSER_LOGFILE, `BROWSER_LOGFILE` defines the location of the file where Firefox log should be stored --> but I don't see the logfile under /dev/null (this file does not exist) Does /dev/null save it to nowhere? – IceTea Apr 01 '19 at 06:44
  • @IceTea checkout this: https://en.wikipedia.org/wiki/Null_device `/dev/null` discards everything, its like a trash – Daniel Eisenreich Nov 19 '19 at 06:52
6

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");
voji
  • 483
  • 4
  • 8
5

Just do this

System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
driver = new FirefoxDriver();
Jonathan
  • 6,741
  • 7
  • 52
  • 69
Akash
  • 115
  • 2
  • 13
3

I am using headless Firefox driver in C#.
To disable geckoDriver logging console, below code it seems to be working for me:

FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(Directory.GetCurrentDirectory());
service.HideCommandPromptWindow = true;
FirefoxOptions options = new FirefoxOptions();
options.AddArguments("--headless");
options.LogLevel = FirefoxDriverLogLevel.Fatal;
WebDriver = new FirefoxDriver(service, options);
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Zeeshan
  • 121
  • 1
  • 3
2

For selenium 3.14.0 , this is working

System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
Shantonu
  • 1,280
  • 13
  • 12
0
  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);
Arun VC
  • 115
  • 3
  • I get an error AND a deprecation warning even if I change it not to give errors anymore. This must be an old version of Selenium – Jonathan Sep 22 '18 at 21:59
0

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
mancocapac
  • 812
  • 6
  • 23
0

This might be a bit hacky but it can quickly get the job done without any coding required. Given that you know the exact location of your file and you run your code on Linux you can just cd into that dir and

rm geckodriver.log
ln -s /dev/null geckodriver.log
teesid
  • 133
  • 1
  • 6
0
profile.setPreference("webdriver.log.init", true);

works, because it fools the webdriver into believing the log has already been initialized, so it won't initialize it and no log will be produced.

user1593165
  • 503
  • 3
  • 6