• Skip to main content
  • Skip to primary sidebar

AutomationTestingHub

Selenium, Appium, Cucumber and more !!!

Disable Firefox Logs with Selenium

November 7, 2017 by anish 4 Comments

This is a short article which shows how you can disable Firefox logs. If you have used some newer versions of GeckoDriver with Firefox, you would have observed that there are a lot of low level logs displayed on the console. These default logs are very low level and sometimes look polluted especially when you have set up your own logs in the code. This article works on addressing this issue.

Disable Firefox Logs – How it works

In this article, we will not supress the GeckoDriver/Marionette logging as such. Our code would just redirect this browser level log to a text file, so that the console looks clean. Let us see how this can be done.

What happens when Firefox logs are not disabled

Let us first launch Firefox the usual way, and see what we get in the logs. The code to launch Firefox is given below:

public static void main(String[] args) {		
	System.setProperty("webdriver.gecko.driver","C:\\selenium_drivers\\geckodriver.exe");
	 
	WebDriver driver = new FirefoxDriver();
	driver.get("http://www.google.com");
	System.out.println("Page Title [1] - " + driver.getTitle());
		
	driver.findElement(By.name("q")).sendKeys("Google");
	driver.findElement(By.name("btnK")).click();
	System.out.println("Page Title [2] - " + driver.getTitle());
}

If you use this code, the console logs would look a bit like this:

Firefox Geckodriver Default Logs

From the above image, you can see that the page titles you printed is displayed among lots of other low level Gecko/Marionette logs. Let us now see how you can clean up these logs.

Code to disable firefox logs

As we had mentioned previously, we will show you the approach using which this GeckoDriver logs can be moved to a separate text file so that the console looks clean. The code for doing this is given below:

System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"C:\\temp\\logs.txt");

Just use the above 2 lines within your code to redirect the logs to a text file (the location of the text file is given in the second line). The complete code to launch firefox is given below –

public static void main(String[] args) {		
	System.setProperty("webdriver.gecko.driver","C:\\selenium_drivers\\geckodriver.exe");
	System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
	System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"C:\\temp\\logs.txt");
		 
	WebDriver driver = new FirefoxDriver();
	driver.get("http://www.google.com");
	System.out.println("Page Title [1] - " + driver.getTitle());
		
	driver.findElement(By.name("q")).sendKeys("Google");
	driver.findElement(By.name("btnK")).click();
	System.out.println("Page Title [2] - " + driver.getTitle());
}

Run the above code and check the Eclipse console. Please note that it only moves the GeckoDriver logs to the text file. The print statements that you put in your code will get displayed in Console itself.

Code to Disable Firefox Logs

You can also navigate to the folder location that you provided in your code to see that the Gecko logs are now stored in the text file.

Geckodriver logs redirected to text file

If you don’t provide any absolute path for the text file, then the file will be saved in your project folder itself. For example, if you just give the location as logs.txt, then this logs file will be saved inside your eclipse project folder.

With this we complete our article on how you can disable firefox logs (or rather redirect firefox logs) with Selenium. Please try out this approach and let us know if this works for you.

Do you use any other approach with which you disable firefox logs? If you do, then you can share your approach with us using the comments section.

We share lots of additional information on Facebook, including interesting articles from other blogs as well. Like our page to get all these updates. See you there!!

Filed Under: Selenium

Primary Sidebar

Automation Testing Hub

Tutorials Guide

Write test scripts in BDD format using our Cucumber Selenium Tutorial

Use our Appium Tutorial Series to setup Appium from scratch

Categories

  • Android
  • Appium
  • Cucumber
  • Java
  • Playwright
  • Selenium
  • Tosca

Recent Posts

  • Appium Inspector – Download and Install
  • How to download Chromedriver for Selenium
  • Run Playwright tests on different browsers
  • Playwright Automation Testing Tutorial
  • Selenium IDE Chrome Download

Recent Comments

  • Run Playwright tests on different browsers - AutomationTestingHub on Playwright Automation Testing Tutorial
  • Confluence: CPSSoft Test Framework on Appium Inspector – Download and Install
  • Playwright Automation Testing Tutorial - AutomationTestingHub on Download and Install – Node.js and NPM
  • Chrome浏览器在使用Java的Appium中无法启动。 | JAVA语言的经验与见解 on 2 Ways to find appPackage and appActivity name of your App
  • Appium Inspector Tutorial - AutomationTestingHub on Download and Install Appium 2 Server

Archives

  • January 2024
  • July 2023
  • March 2023
  • February 2023
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016

Latest Selenium 3 Guide

Are you using the latest version of Selenium WebDriver? It provides lot better support for the latest browser versions. Check it out here - Setup Latest Selenium WebDriver

Categories

  • Android
  • Appium
  • Cucumber
  • Java
  • Playwright
  • Selenium
  • Tosca

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in

Go to mobile version