Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Getting console.log output from Firefox with Selenium.



We can get console.log output from Firefox with Selenium. This is done with the setProperty method.FirefoxDriver.SystemProperty.BROWSER_LOGFILE and the path of the file in which the logs are to be captured are passed as parameters to that method.

Syntax

System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "FFLogs.txt");

After refreshing the project folder, we shall get the FFLogs.txt file where the logs shall be captured.

Example

Code Implementation.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.logging.LogType;
public class FirefoxLogs{
   public static void main(String[] args) {
      System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");
      // set the System Property to BROWSER_LOGFILE and path of log file
      System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "FFLogs.txt");
      WebDriver driver = new FirefoxDriver();
      driver.get("https://www.tutorialspoint.com/tutor_connect/index.php");
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      // identify element
      driver.findElement(By.id("txtSearchText")).sendKeys("Selenium");
      driver.quit();
   }
}

Output

A log file with the name FFLogs.txt gets created within the project folder.

Updated on: 2020-12-28T11:33:09+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements