Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get client-side logs in Selenium

Tags:

c#

selenium

I'm using Selenium in C# and would like to read the client-side logs (like console.log in javascript).

I'm initializing the ChromeDriver and setting the logging preference to Client:

ChromeOptions options = new ChromeOptions();
options.SetLoggingPreference(LogType.Client, LogLevel.All);
var webDriver = new ChromeDriver(options);
objectContainer.RegisterInstanceAs<IWebDriver>(webDriver);

However, when I try to retrieve the AvailableLogTypes:

var whatever = driver.Manage().Logs.AvailableLogTypes;

browser and driver are the only available log types to read from:

enter image description here

When I try to get the Client logs:

var logs = driver.Manage().Logs.GetLog(LogType.Client);

I get an exception:

An exception of type 'System.InvalidOperationException' occurred in WebDriver.dll but was not handled in user code

Additional information: unknown error: log type 'client' not found

Any idea how I can fix this? It seems like it defaults back to browser and driver logging at some point but I'm not sure where.

like image 411
tnw Avatar asked Jan 19 '17 16:01

tnw


1 Answers

If you want logs like console.log(), then I think LogType.Browser is what you need. Just make sure, the browser has those logs

If you don't see other LogType, like CLIENT, SERVER... you can try to enable those log types as the answer in How to obtain native logger in Selenium WebDriver

like image 96
Linh Nguyen Avatar answered Oct 24 '22 20:10

Linh Nguyen