Get chrome's console log

后端 未结 8 1410
感动是毒
感动是毒 2020-11-28 09:05

I want to build an automation testing, so I have to know the errors that appear in the console of chrome.

there is an option to get the error lines that appear in th

相关标签:
8条回答
  • 2020-11-28 09:28

    As per issue 6832 logging is not implemented yet for C# bindings. So there might not be an easy way to get this working as of now.

    0 讨论(0)
  • 2020-11-28 09:30

    C# bindings to the Chrome console logs are finally available in Selenium 4.0.0-alpha05. Selenium 3.141.0 and prior do not have support.

    Before instantiating a new ChromeDriver object, set the logging preference in a ChromeOptions object and pass that into ChromeDriver:

    ChromeOptions options = new ChromeOptions();   
    options.SetLoggingPreference(LogType.Browser, LogLevel.All);
    ChromeDriver driver = new ChromeDriver(options);
    

    Then, to write the Chrome console logs to a flat file:

        public void WriteConsoleErrors()
        {
            string strPath = "C:\\ConsoleErrors.txt";
            if (!File.Exists(strPath))
            {
                File.Create(strPath).Dispose();
            }
    
            using (StreamWriter sw = File.AppendText(strPath))
            {
                var entries = driver.Manage().Logs.GetLog(LogType.Browser);
                foreach (var entry in entries)
                {
                    sw.WriteLine(entry.ToString());
                }
            }
        }
    
    0 讨论(0)
提交回复
热议问题