How do I disable Firefox logging in Selenium using

2019-04-04 17:08发布

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.

7条回答
神经病院院长
2楼-- · 2019-04-04 17:48

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
查看更多
霸刀☆藐视天下
3楼-- · 2019-04-04 17:49
  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);
查看更多
Melony?
4楼-- · 2019-04-04 17:53

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();
查看更多
仙女界的扛把子
5楼-- · 2019-04-04 17:56

For selenium 3.14.0 , this is working

System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
查看更多
神经病院院长
6楼-- · 2019-04-04 17:57

Just do this

System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
driver = new FirefoxDriver();
查看更多
虎瘦雄心在
7楼-- · 2019-04-04 18:02
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"
)
查看更多
登录 后发表回答