I'm writing selenium tests which are launch on the firefox (gecko) driver.

If a test fails, I want to retrieve the log present on the firefox js console.

In order to do that, I have added the following into my code:

On the "Before" statement:

LoggingPreferences logs = new LoggingPreferences();
logs.enable(LogType.BROWSER, Level.ALL);
logs.enable(LogType.DRIVER, Level.ALL);
logs.enable(LogType.CLIENT, Level.ALL);
logs.enable(LogType.PERFORMANCE, Level.ALL);
logs.enable(LogType.PROFILER, Level.ALL);
logs.enable(LogType.SERVER, Level.ALL);
options.setCapability(CapabilityType.LOGGING_PREFS, logs);
driver = new FirefoxDriver(options);

On the "After" statement:

   try {
        FileOutputStream out = new FileOutputStream("target/surefire-reports/consoleLog-" + fileName + ".log");

        List<LogEntry> myLogs = driver.manage().logs().get(LogType.BROWSER).getAll();
        for (int i = 0; i < myLogs.size(); i++){

However, when this is run, I got the following error:

org.openqa.selenium.UnsupportedCommandException: POST /session/a6064f0a-713c-4f55-9a17-f6d80f4c457d/log did not match a known command

After doing some research, it turns out that The Selenium log API is not (yet?) supported by geckodriver. (source: link 1, link 2)


So, is there some other way around to accomplish what I want to accomplish? (using Chrome instead of Firefox is not a solution).


2 Answers 2


Try this piece of code and see if you get the logs:

WebDriver driver;
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "//geckodriver");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "FFLogs.txt");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
// identify element


Reference: https://www.tutorialspoint.com/getting-console-log-output-from-firefox-with-selenium


If you can't access the logs via the webdriver, you can maybe work around it by adding the logs to the DOM with the JavascriptExecutor. With the JavascriptExecutor it may be possible to insert this script into the page to capture an error. Though this will most likely not help when the error already happened.

You can ask the frontend developers if they could add the mentioned script to every page to make test automation easier for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.