0

I'm struggling to get the network developer logs for performance testing. Below is the code I'm using and here is the error i'm experiencing. I'm kind of stuck and not entirely sure of why I'm unable to initialize my ChromeDriver. How do you properly retrieve the network devtools logs for performance?

OpenQA.Selenium.WebDriverException: 'invalid argument: entry 0 of 'firstMatch' is invalid from invalid argument: perfLoggingPrefs specified, but performance logging was not enabled'

public Driver(ChromeDriverModel chromeDriverModel)
        {
            ChromeOptions chromeOptions = new ChromeOptions();
            enablePerformanceMonitor = chromeDriverModel.enablePerformanceMonitoring;
            if (enablePerformanceMonitor)
                chromeOptions = _ChromePerformanceOptions();

            if (!string.IsNullOrWhiteSpace(chromeDriverModel.ChromeDriverLocation))
            {
                if (enablePerformanceMonitor)
                    _webDriver = new ChromeDriver(chromeDriverModel.ChromeDriverLocation, chromeOptions);
                else
                    _webDriver = new ChromeDriver(chromeDriverModel.ChromeDriverLocation);
            }
            else
            {
                if (enablePerformanceMonitor)
                    _webDriver = new ChromeDriver(chromeOptions);
                else
                    _webDriver = new ChromeDriver();
            }
        }


private ChromeOptions _ChromePerformanceOptions()
        {
            var option = new ChromeOptions();
            var perfLogPrefs = new ChromePerformanceLoggingPreferences();
            perfLogPrefs.AddTracingCategories(new string[] { "devtools.network", "devtools.timeline" });
            option.PerformanceLoggingPreferences = perfLogPrefs;
            option.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
            option.SetLoggingPreference("performance", LogLevel.All);
            return option;
        }

The questions are not the same, LoggingPreferences and DesiredCapibiliies have been deprecated in 3.141.0

JL1
  • 309
  • 2
  • 18
  • Possible duplicate of [how to access Network panel on google chrome developer tools with selenium?](https://stackoverflow.com/questions/20401264/how-to-access-network-panel-on-google-chrome-developer-tools-with-selenium) – orde Jun 27 '19 at 17:00
  • This is a bug between the .NET bindings and Chrome/chromedriver 75, which enabled W3C WebDriver Specification mode as the default for the first time. – JimEvans Jun 28 '19 at 13:50
  • 1
    @JimEvans I was reading the same thing, but what's the work around? Do I just go to beta 76? Or how can i disabled W3C? I tried the goog:LoggingPrefs and still no go – JL1 Jun 28 '19 at 15:29

2 Answers2

0

You need to enable the performance logging.

LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
Arun Nair
  • 425
  • 3
  • 11
  • LoggingPreferences seems to be depricated in 3.141, at least i cannot find it in OpenQA.Selenium – JL1 Jun 27 '19 at 17:34
  • as a follow up there is ChromePerformanceLoggingPreferences however, I don't see any clear indication on how to enable – JL1 Jun 27 '19 at 17:37
0

Not sure if you were able to find any solution. As of now, I am using Selenium Webdriver v3.141 and Selenium.Chrome.WebDriver v2.35 and I am able to get the performance logs.

ChromeOptions options = new ChromeOptions();
var perfLogPrefs = new ChromePerformanceLoggingPreferences();
options.PerformanceLoggingPreferences = perfLogPrefs;
options.SetLoggingPreference("performance", LogLevel.All);

//Write code to launch driver and application url

//prints the logs
for (int i = 0; i < logs.Count; i++)
{
    Console.WriteLine(logs[i].Message);
}

Note: I am still not able to find a solution to extract performance logs using latest Selenium Chrome driver

Subba Changa
  • 194
  • 2
  • 15
  • Please see below for the solution with latest version of Selenium.https://stackoverflow.com/questions/58650522/unable-to-get-chrome-performance-logs-in-selenium-c-sharp/60553029#60553029 – Subba Changa Jun 22 '20 at 21:23