Here's Java code that does the job, I hope you can translate it to C#
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.logging.LogEntries;
import org.openqa.selenium.logging.LogEntry;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class ChromeConsoleLogging
private WebDriver driver;
@BeforeMethod
public void setUp() {
System.setProperty(
@AfterMethod
public void tearDown()
public void analyzeLog()
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
for (LogEntry entry : logEntries) {
System.out.println(new Date(entry.getTimestamp()) +
}
@Test
public void testMethod()
driver.get(
}
Pay attention to the setUp method in the above code. We use the LoggingPreferences object to enable logging. There are a few kinds of logs, but if you want to track console errors then LogType.BROWSER is the one that you must use. Then we pass that object to DesiredCapabilities and further to ChromeDriver constructor, then we will have an instance of ChromeDriver with logging enabled.
After performing some actions on the page we call the analyzeLog() method.
Here we tend to merely extract the log and reiterate through its entries.
Here you'll place assertions or do the other reporting you would like.