Not able to get Logs in Gecko Driver in Selenium 4.0

203 views
Skip to first unread message

Sagar Gulhane

unread,
Mar 13, 2023, 8:55:22 AM3/13/23
to Selenium Users
I am able to get logs form Chrome and MS Edge drivers using options in selenium 4.0  but same code is not working for Gecko Driver (Firefox). 

I am suing C# as scripting language. 

Below is code I am using for Chrome : 

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.SetLoggingPreference(LogType.Performance, LogLevel.All);
IWebDriver driver = new ChromeDriver(chromeOptions);
driver.Navigate().GoToUrl("{My Application URL}");

 IWebElement ElementToClick = driver.FindElement(By.XPath({XPath of Element}));
 ElementToClick.Click();

List<LogEntry> primaryLogs = driver.Manage().Logs.GetLog(LogType.Performance);

Below is code I am using for Gecko Driver which is not returning any value in  primaryLogs : 

FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.SetLoggingPreference(LogType.Performance, LogLevel.All);
IWebDriver driver = new FirefoxDriver(firefoxOptions);
driver.Navigate().GoToUrl("{My Application URL}");

 IWebElement ElementToClick = driver.FindElement(By.XPath({XPath of Element}));
 ElementToClick.Click();

List<LogEntry> primaryLogs = driver.Manage().Logs.GetLog(LogType.Performance);

Appreciate help on this. 

rkms_82

unread,
Mar 13, 2023, 2:26:00 PM3/13/23
to Selenium Users
Here's an example code snippet in Java to get the logs from Gecko Driver using Selenium 4.0

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.logging.LogEntry;
import org.openqa.selenium.logging.LogType;

import java.util.List;

public class GeckoDriverLogsExample {
    public static void main(String[] args) {
        // Create a Firefox instance
        WebDriver driver = new FirefoxDriver();

        // Navigate to a website
        driver.get("https://www.example.com");

        // Get the browser logs
        List<LogEntry> logs = driver.manage().logs().get(LogType.BROWSER).getAll();

        // Print the logs
        for (LogEntry log : logs) {
            System.out.println(log.getMessage());
        }

        // Quit the driver
        driver.quit();

Sagar Gulhane

unread,
Mar 17, 2023, 6:10:19 AM3/17/23
to Selenium Users
Thanks for your reply the same thing I have implemented as per C# format. But its not working for me. :-(
Reply all
Reply to author
Forward
0 new messages