Get chrome's console log










20















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 the console?



In order to see the console: right click somewhere in the page, click "inspect element" and then go to "console".










share|improve this question

















  • 2





    Does this help? stackoverflow.com/questions/5056737/…

    – Grim...
    Aug 15 '13 at 20:36















20















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 the console?



In order to see the console: right click somewhere in the page, click "inspect element" and then go to "console".










share|improve this question

















  • 2





    Does this help? stackoverflow.com/questions/5056737/…

    – Grim...
    Aug 15 '13 at 20:36













20












20








20


9






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 the console?



In order to see the console: right click somewhere in the page, click "inspect element" and then go to "console".










share|improve this question














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 the console?



In order to see the console: right click somewhere in the page, click "inspect element" and then go to "console".







c# javascript asp.net-mvc selenium






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 15 '13 at 20:35









Alon ShmielAlon Shmiel

1,1661666113




1,1661666113







  • 2





    Does this help? stackoverflow.com/questions/5056737/…

    – Grim...
    Aug 15 '13 at 20:36












  • 2





    Does this help? stackoverflow.com/questions/5056737/…

    – Grim...
    Aug 15 '13 at 20:36







2




2





Does this help? stackoverflow.com/questions/5056737/…

– Grim...
Aug 15 '13 at 20:36





Does this help? stackoverflow.com/questions/5056737/…

– Grim...
Aug 15 '13 at 20:36












6 Answers
6






active

oldest

votes


















29














I don't know C# but 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("webdriver.chrome.driver", "c:\path\to\chromedriver.exe");
DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
driver = new ChromeDriver(caps);


@AfterMethod
public void tearDown()
driver.quit();


public void analyzeLog()
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
for (LogEntry entry : logEntries)
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
//do something useful with the data



@Test
public void testMethod()
driver.get("http://mypage.com");
//do something on page
analyzeLog();




Pay attention to setUp method in above code. We use LoggingPreferences object to enable logging. There are a few types of logs, but if you want to track console errors then LogType.BROWSER is the one that you should use. Then we pass that object to DesiredCapabilities and further to ChromeDriver constructor and voila - we have an instance of ChromeDriver with logging enabled.



After performing some actions on page we call analyzeLog() method. Here we simply extract the log and iterate through its entries. Here you can put assertions or do any other reporting you want.



My inspiration was this code by Michael Klepikov that explains how to extract performance logs from ChromeDriver.






share|improve this answer




















  • 7





    Whilst this is the correct answer for Java, as you point out, it's not C# and wouldn't work for C# once "translated" because the .NET API of Selenium doesn't support logs. As in, when you do Driver.Manage(), .Logs() will not be available. +1 anyway, since it shows the solution.

    – Arran
    Aug 18 '13 at 9:39












  • Is there still no way of getting Browser logs in C#?

    – Sakshi Singla
    May 29 '15 at 9:11











  • I'm not sure why issue 6832 is still open, but for now .Logs works. We have WebDriver version 2.21, probably

    – mazharenko
    Apr 28 '16 at 9:48











  • So with your idea and code like this: var logs = driver.Manage().Logs.GetLog(LogType.Browser); I still cannot get the logs. May you please check this issue over here? Thanks in advance!

    – Tomasz Tarnowski
    May 4 '16 at 13:02







  • 1





    Why is the Java-based answer marked as the correct one, instead of the C# solution?

    – Agent Shoulder
    Oct 5 '16 at 4:47


















17














You can get logs this way:



Driver().Manage().Logs.GetLog();


By specifying what log you are interested in you can get the browser log, that is:



Driver().Manage().Logs.GetLog(LogType.Browser);


Also remember to setup your driver accordingly:



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





share|improve this answer

























  • Hi! It's not working for me, can you please check my issue? Thanks!

    – Tomasz Tarnowski
    May 4 '16 at 13:03











  • @BlackHat Sorry for the late reply! I updated my answer with the info from your thread.

    – Agent Shoulder
    May 10 '16 at 5:01











  • I did not have to set up logging mechanism when when starting the driver and Driver().Manage().Logs.GetLog(LogType.Browser); got me LogEntries containing error

    – Tarun
    Jul 11 '16 at 13:21











  • Isn't that exactly what's intended here? @Tarun

    – Agent Shoulder
    Feb 28 '17 at 13:32











  • Thanks, this worked for me!

    – Rene Willems
    Dec 21 '17 at 10:23


















4














This is the c# code for logging the brower log from chrome.



private void CheckLogs()

List<LogEntry> logs = Driver.Manage().Logs.GetLog(LogType.Browser).ToList();
foreach (LogEntry log in logs)

Log(log.Message);




here is my code for the actual log:



 public void Log(string value, params object values)

// allow indenting
if (!String.IsNullOrEmpty(value) && value.Length > 0 && value.Substring(0, 1) != "*")

value = " " + value;


// write the log
Console.WriteLine(String.Format(value, values));






share|improve this answer






























    1














    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.






    share|improve this answer























    • As far as I know - this should be the answer. There is not (to my knowledge) way to get the browser logs natively in Selenium with the C# language. Some of the comments mentioned it may be removed form other language bindings as well. I will be very happy to sew newer information about this but I think the latest one is - you're not going to have it.

      – Pavel Donchev
      Dec 28 '18 at 8:01











    • Yes there is, @PavelDonchev - check my answer above..

      – Agent Shoulder
      Jan 23 at 17:08


















    0














    driver.manage().logs().get("browser")


    Gets all logs printed on the console. I was able to get all logs except Violations. Please have a look here Chrome Console logs not printing Violations






    share|improve this answer






























      0














      public void Test_DetectMissingFilesToLoadWebpage()

      try

      List<LogEntry> logs = driver.Manage().Logs.GetLog(LogType.Browser).ToList();
      foreach (LogEntry log in logs)

      while(logs.Count > 0)

      String logInfo = log.ToString();
      if (log.Message.Contains("Failed to load resource: the server responded with a status of 404 (Not Found)"))

      Assert.Fail();

      else

      Assert.Pass();




      catch (NoSuchElementException e)

      test.Fail(e.StackTrace);




      You could do something like this in C#. It is a complete test case. Then print the console output as String i.e logInfo in your report. For some reason, Log(log.Message) from the solution above this one gave me build errors.So, I replaced it.






      share|improve this answer
























        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18261338%2fget-chromes-console-log%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        29














        I don't know C# but 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("webdriver.chrome.driver", "c:\path\to\chromedriver.exe");
        DesiredCapabilities caps = DesiredCapabilities.chrome();
        LoggingPreferences logPrefs = new LoggingPreferences();
        logPrefs.enable(LogType.BROWSER, Level.ALL);
        caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
        driver = new ChromeDriver(caps);


        @AfterMethod
        public void tearDown()
        driver.quit();


        public void analyzeLog()
        LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
        for (LogEntry entry : logEntries)
        System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
        //do something useful with the data



        @Test
        public void testMethod()
        driver.get("http://mypage.com");
        //do something on page
        analyzeLog();




        Pay attention to setUp method in above code. We use LoggingPreferences object to enable logging. There are a few types of logs, but if you want to track console errors then LogType.BROWSER is the one that you should use. Then we pass that object to DesiredCapabilities and further to ChromeDriver constructor and voila - we have an instance of ChromeDriver with logging enabled.



        After performing some actions on page we call analyzeLog() method. Here we simply extract the log and iterate through its entries. Here you can put assertions or do any other reporting you want.



        My inspiration was this code by Michael Klepikov that explains how to extract performance logs from ChromeDriver.






        share|improve this answer




















        • 7





          Whilst this is the correct answer for Java, as you point out, it's not C# and wouldn't work for C# once "translated" because the .NET API of Selenium doesn't support logs. As in, when you do Driver.Manage(), .Logs() will not be available. +1 anyway, since it shows the solution.

          – Arran
          Aug 18 '13 at 9:39












        • Is there still no way of getting Browser logs in C#?

          – Sakshi Singla
          May 29 '15 at 9:11











        • I'm not sure why issue 6832 is still open, but for now .Logs works. We have WebDriver version 2.21, probably

          – mazharenko
          Apr 28 '16 at 9:48











        • So with your idea and code like this: var logs = driver.Manage().Logs.GetLog(LogType.Browser); I still cannot get the logs. May you please check this issue over here? Thanks in advance!

          – Tomasz Tarnowski
          May 4 '16 at 13:02







        • 1





          Why is the Java-based answer marked as the correct one, instead of the C# solution?

          – Agent Shoulder
          Oct 5 '16 at 4:47















        29














        I don't know C# but 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("webdriver.chrome.driver", "c:\path\to\chromedriver.exe");
        DesiredCapabilities caps = DesiredCapabilities.chrome();
        LoggingPreferences logPrefs = new LoggingPreferences();
        logPrefs.enable(LogType.BROWSER, Level.ALL);
        caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
        driver = new ChromeDriver(caps);


        @AfterMethod
        public void tearDown()
        driver.quit();


        public void analyzeLog()
        LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
        for (LogEntry entry : logEntries)
        System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
        //do something useful with the data



        @Test
        public void testMethod()
        driver.get("http://mypage.com");
        //do something on page
        analyzeLog();




        Pay attention to setUp method in above code. We use LoggingPreferences object to enable logging. There are a few types of logs, but if you want to track console errors then LogType.BROWSER is the one that you should use. Then we pass that object to DesiredCapabilities and further to ChromeDriver constructor and voila - we have an instance of ChromeDriver with logging enabled.



        After performing some actions on page we call analyzeLog() method. Here we simply extract the log and iterate through its entries. Here you can put assertions or do any other reporting you want.



        My inspiration was this code by Michael Klepikov that explains how to extract performance logs from ChromeDriver.






        share|improve this answer




















        • 7





          Whilst this is the correct answer for Java, as you point out, it's not C# and wouldn't work for C# once "translated" because the .NET API of Selenium doesn't support logs. As in, when you do Driver.Manage(), .Logs() will not be available. +1 anyway, since it shows the solution.

          – Arran
          Aug 18 '13 at 9:39












        • Is there still no way of getting Browser logs in C#?

          – Sakshi Singla
          May 29 '15 at 9:11











        • I'm not sure why issue 6832 is still open, but for now .Logs works. We have WebDriver version 2.21, probably

          – mazharenko
          Apr 28 '16 at 9:48











        • So with your idea and code like this: var logs = driver.Manage().Logs.GetLog(LogType.Browser); I still cannot get the logs. May you please check this issue over here? Thanks in advance!

          – Tomasz Tarnowski
          May 4 '16 at 13:02







        • 1





          Why is the Java-based answer marked as the correct one, instead of the C# solution?

          – Agent Shoulder
          Oct 5 '16 at 4:47













        29












        29








        29







        I don't know C# but 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("webdriver.chrome.driver", "c:\path\to\chromedriver.exe");
        DesiredCapabilities caps = DesiredCapabilities.chrome();
        LoggingPreferences logPrefs = new LoggingPreferences();
        logPrefs.enable(LogType.BROWSER, Level.ALL);
        caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
        driver = new ChromeDriver(caps);


        @AfterMethod
        public void tearDown()
        driver.quit();


        public void analyzeLog()
        LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
        for (LogEntry entry : logEntries)
        System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
        //do something useful with the data



        @Test
        public void testMethod()
        driver.get("http://mypage.com");
        //do something on page
        analyzeLog();




        Pay attention to setUp method in above code. We use LoggingPreferences object to enable logging. There are a few types of logs, but if you want to track console errors then LogType.BROWSER is the one that you should use. Then we pass that object to DesiredCapabilities and further to ChromeDriver constructor and voila - we have an instance of ChromeDriver with logging enabled.



        After performing some actions on page we call analyzeLog() method. Here we simply extract the log and iterate through its entries. Here you can put assertions or do any other reporting you want.



        My inspiration was this code by Michael Klepikov that explains how to extract performance logs from ChromeDriver.






        share|improve this answer















        I don't know C# but 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("webdriver.chrome.driver", "c:\path\to\chromedriver.exe");
        DesiredCapabilities caps = DesiredCapabilities.chrome();
        LoggingPreferences logPrefs = new LoggingPreferences();
        logPrefs.enable(LogType.BROWSER, Level.ALL);
        caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
        driver = new ChromeDriver(caps);


        @AfterMethod
        public void tearDown()
        driver.quit();


        public void analyzeLog()
        LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
        for (LogEntry entry : logEntries)
        System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
        //do something useful with the data



        @Test
        public void testMethod()
        driver.get("http://mypage.com");
        //do something on page
        analyzeLog();




        Pay attention to setUp method in above code. We use LoggingPreferences object to enable logging. There are a few types of logs, but if you want to track console errors then LogType.BROWSER is the one that you should use. Then we pass that object to DesiredCapabilities and further to ChromeDriver constructor and voila - we have an instance of ChromeDriver with logging enabled.



        After performing some actions on page we call analyzeLog() method. Here we simply extract the log and iterate through its entries. Here you can put assertions or do any other reporting you want.



        My inspiration was this code by Michael Klepikov that explains how to extract performance logs from ChromeDriver.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Aug 17 '13 at 0:24

























        answered Aug 17 '13 at 0:15









        JacekMJacekM

        3,09712132




        3,09712132







        • 7





          Whilst this is the correct answer for Java, as you point out, it's not C# and wouldn't work for C# once "translated" because the .NET API of Selenium doesn't support logs. As in, when you do Driver.Manage(), .Logs() will not be available. +1 anyway, since it shows the solution.

          – Arran
          Aug 18 '13 at 9:39












        • Is there still no way of getting Browser logs in C#?

          – Sakshi Singla
          May 29 '15 at 9:11











        • I'm not sure why issue 6832 is still open, but for now .Logs works. We have WebDriver version 2.21, probably

          – mazharenko
          Apr 28 '16 at 9:48











        • So with your idea and code like this: var logs = driver.Manage().Logs.GetLog(LogType.Browser); I still cannot get the logs. May you please check this issue over here? Thanks in advance!

          – Tomasz Tarnowski
          May 4 '16 at 13:02







        • 1





          Why is the Java-based answer marked as the correct one, instead of the C# solution?

          – Agent Shoulder
          Oct 5 '16 at 4:47












        • 7





          Whilst this is the correct answer for Java, as you point out, it's not C# and wouldn't work for C# once "translated" because the .NET API of Selenium doesn't support logs. As in, when you do Driver.Manage(), .Logs() will not be available. +1 anyway, since it shows the solution.

          – Arran
          Aug 18 '13 at 9:39












        • Is there still no way of getting Browser logs in C#?

          – Sakshi Singla
          May 29 '15 at 9:11











        • I'm not sure why issue 6832 is still open, but for now .Logs works. We have WebDriver version 2.21, probably

          – mazharenko
          Apr 28 '16 at 9:48











        • So with your idea and code like this: var logs = driver.Manage().Logs.GetLog(LogType.Browser); I still cannot get the logs. May you please check this issue over here? Thanks in advance!

          – Tomasz Tarnowski
          May 4 '16 at 13:02







        • 1





          Why is the Java-based answer marked as the correct one, instead of the C# solution?

          – Agent Shoulder
          Oct 5 '16 at 4:47







        7




        7





        Whilst this is the correct answer for Java, as you point out, it's not C# and wouldn't work for C# once "translated" because the .NET API of Selenium doesn't support logs. As in, when you do Driver.Manage(), .Logs() will not be available. +1 anyway, since it shows the solution.

        – Arran
        Aug 18 '13 at 9:39






        Whilst this is the correct answer for Java, as you point out, it's not C# and wouldn't work for C# once "translated" because the .NET API of Selenium doesn't support logs. As in, when you do Driver.Manage(), .Logs() will not be available. +1 anyway, since it shows the solution.

        – Arran
        Aug 18 '13 at 9:39














        Is there still no way of getting Browser logs in C#?

        – Sakshi Singla
        May 29 '15 at 9:11





        Is there still no way of getting Browser logs in C#?

        – Sakshi Singla
        May 29 '15 at 9:11













        I'm not sure why issue 6832 is still open, but for now .Logs works. We have WebDriver version 2.21, probably

        – mazharenko
        Apr 28 '16 at 9:48





        I'm not sure why issue 6832 is still open, but for now .Logs works. We have WebDriver version 2.21, probably

        – mazharenko
        Apr 28 '16 at 9:48













        So with your idea and code like this: var logs = driver.Manage().Logs.GetLog(LogType.Browser); I still cannot get the logs. May you please check this issue over here? Thanks in advance!

        – Tomasz Tarnowski
        May 4 '16 at 13:02






        So with your idea and code like this: var logs = driver.Manage().Logs.GetLog(LogType.Browser); I still cannot get the logs. May you please check this issue over here? Thanks in advance!

        – Tomasz Tarnowski
        May 4 '16 at 13:02





        1




        1





        Why is the Java-based answer marked as the correct one, instead of the C# solution?

        – Agent Shoulder
        Oct 5 '16 at 4:47





        Why is the Java-based answer marked as the correct one, instead of the C# solution?

        – Agent Shoulder
        Oct 5 '16 at 4:47













        17














        You can get logs this way:



        Driver().Manage().Logs.GetLog();


        By specifying what log you are interested in you can get the browser log, that is:



        Driver().Manage().Logs.GetLog(LogType.Browser);


        Also remember to setup your driver accordingly:



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





        share|improve this answer

























        • Hi! It's not working for me, can you please check my issue? Thanks!

          – Tomasz Tarnowski
          May 4 '16 at 13:03











        • @BlackHat Sorry for the late reply! I updated my answer with the info from your thread.

          – Agent Shoulder
          May 10 '16 at 5:01











        • I did not have to set up logging mechanism when when starting the driver and Driver().Manage().Logs.GetLog(LogType.Browser); got me LogEntries containing error

          – Tarun
          Jul 11 '16 at 13:21











        • Isn't that exactly what's intended here? @Tarun

          – Agent Shoulder
          Feb 28 '17 at 13:32











        • Thanks, this worked for me!

          – Rene Willems
          Dec 21 '17 at 10:23















        17














        You can get logs this way:



        Driver().Manage().Logs.GetLog();


        By specifying what log you are interested in you can get the browser log, that is:



        Driver().Manage().Logs.GetLog(LogType.Browser);


        Also remember to setup your driver accordingly:



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





        share|improve this answer

























        • Hi! It's not working for me, can you please check my issue? Thanks!

          – Tomasz Tarnowski
          May 4 '16 at 13:03











        • @BlackHat Sorry for the late reply! I updated my answer with the info from your thread.

          – Agent Shoulder
          May 10 '16 at 5:01











        • I did not have to set up logging mechanism when when starting the driver and Driver().Manage().Logs.GetLog(LogType.Browser); got me LogEntries containing error

          – Tarun
          Jul 11 '16 at 13:21











        • Isn't that exactly what's intended here? @Tarun

          – Agent Shoulder
          Feb 28 '17 at 13:32











        • Thanks, this worked for me!

          – Rene Willems
          Dec 21 '17 at 10:23













        17












        17








        17







        You can get logs this way:



        Driver().Manage().Logs.GetLog();


        By specifying what log you are interested in you can get the browser log, that is:



        Driver().Manage().Logs.GetLog(LogType.Browser);


        Also remember to setup your driver accordingly:



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





        share|improve this answer















        You can get logs this way:



        Driver().Manage().Logs.GetLog();


        By specifying what log you are interested in you can get the browser log, that is:



        Driver().Manage().Logs.GetLog(LogType.Browser);


        Also remember to setup your driver accordingly:



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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited May 10 '16 at 4:56

























        answered Apr 29 '16 at 7:35









        Agent ShoulderAgent Shoulder

        331214




        331214












        • Hi! It's not working for me, can you please check my issue? Thanks!

          – Tomasz Tarnowski
          May 4 '16 at 13:03











        • @BlackHat Sorry for the late reply! I updated my answer with the info from your thread.

          – Agent Shoulder
          May 10 '16 at 5:01











        • I did not have to set up logging mechanism when when starting the driver and Driver().Manage().Logs.GetLog(LogType.Browser); got me LogEntries containing error

          – Tarun
          Jul 11 '16 at 13:21











        • Isn't that exactly what's intended here? @Tarun

          – Agent Shoulder
          Feb 28 '17 at 13:32











        • Thanks, this worked for me!

          – Rene Willems
          Dec 21 '17 at 10:23

















        • Hi! It's not working for me, can you please check my issue? Thanks!

          – Tomasz Tarnowski
          May 4 '16 at 13:03











        • @BlackHat Sorry for the late reply! I updated my answer with the info from your thread.

          – Agent Shoulder
          May 10 '16 at 5:01











        • I did not have to set up logging mechanism when when starting the driver and Driver().Manage().Logs.GetLog(LogType.Browser); got me LogEntries containing error

          – Tarun
          Jul 11 '16 at 13:21











        • Isn't that exactly what's intended here? @Tarun

          – Agent Shoulder
          Feb 28 '17 at 13:32











        • Thanks, this worked for me!

          – Rene Willems
          Dec 21 '17 at 10:23
















        Hi! It's not working for me, can you please check my issue? Thanks!

        – Tomasz Tarnowski
        May 4 '16 at 13:03





        Hi! It's not working for me, can you please check my issue? Thanks!

        – Tomasz Tarnowski
        May 4 '16 at 13:03













        @BlackHat Sorry for the late reply! I updated my answer with the info from your thread.

        – Agent Shoulder
        May 10 '16 at 5:01





        @BlackHat Sorry for the late reply! I updated my answer with the info from your thread.

        – Agent Shoulder
        May 10 '16 at 5:01













        I did not have to set up logging mechanism when when starting the driver and Driver().Manage().Logs.GetLog(LogType.Browser); got me LogEntries containing error

        – Tarun
        Jul 11 '16 at 13:21





        I did not have to set up logging mechanism when when starting the driver and Driver().Manage().Logs.GetLog(LogType.Browser); got me LogEntries containing error

        – Tarun
        Jul 11 '16 at 13:21













        Isn't that exactly what's intended here? @Tarun

        – Agent Shoulder
        Feb 28 '17 at 13:32





        Isn't that exactly what's intended here? @Tarun

        – Agent Shoulder
        Feb 28 '17 at 13:32













        Thanks, this worked for me!

        – Rene Willems
        Dec 21 '17 at 10:23





        Thanks, this worked for me!

        – Rene Willems
        Dec 21 '17 at 10:23











        4














        This is the c# code for logging the brower log from chrome.



        private void CheckLogs()

        List<LogEntry> logs = Driver.Manage().Logs.GetLog(LogType.Browser).ToList();
        foreach (LogEntry log in logs)

        Log(log.Message);




        here is my code for the actual log:



         public void Log(string value, params object values)

        // allow indenting
        if (!String.IsNullOrEmpty(value) && value.Length > 0 && value.Substring(0, 1) != "*")

        value = " " + value;


        // write the log
        Console.WriteLine(String.Format(value, values));






        share|improve this answer



























          4














          This is the c# code for logging the brower log from chrome.



          private void CheckLogs()

          List<LogEntry> logs = Driver.Manage().Logs.GetLog(LogType.Browser).ToList();
          foreach (LogEntry log in logs)

          Log(log.Message);




          here is my code for the actual log:



           public void Log(string value, params object values)

          // allow indenting
          if (!String.IsNullOrEmpty(value) && value.Length > 0 && value.Substring(0, 1) != "*")

          value = " " + value;


          // write the log
          Console.WriteLine(String.Format(value, values));






          share|improve this answer

























            4












            4








            4







            This is the c# code for logging the brower log from chrome.



            private void CheckLogs()

            List<LogEntry> logs = Driver.Manage().Logs.GetLog(LogType.Browser).ToList();
            foreach (LogEntry log in logs)

            Log(log.Message);




            here is my code for the actual log:



             public void Log(string value, params object values)

            // allow indenting
            if (!String.IsNullOrEmpty(value) && value.Length > 0 && value.Substring(0, 1) != "*")

            value = " " + value;


            // write the log
            Console.WriteLine(String.Format(value, values));






            share|improve this answer













            This is the c# code for logging the brower log from chrome.



            private void CheckLogs()

            List<LogEntry> logs = Driver.Manage().Logs.GetLog(LogType.Browser).ToList();
            foreach (LogEntry log in logs)

            Log(log.Message);




            here is my code for the actual log:



             public void Log(string value, params object values)

            // allow indenting
            if (!String.IsNullOrEmpty(value) && value.Length > 0 && value.Substring(0, 1) != "*")

            value = " " + value;


            // write the log
            Console.WriteLine(String.Format(value, values));







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 28 '16 at 16:27









            Beau BridgesBeau Bridges

            411




            411





















                1














                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.






                share|improve this answer























                • As far as I know - this should be the answer. There is not (to my knowledge) way to get the browser logs natively in Selenium with the C# language. Some of the comments mentioned it may be removed form other language bindings as well. I will be very happy to sew newer information about this but I think the latest one is - you're not going to have it.

                  – Pavel Donchev
                  Dec 28 '18 at 8:01











                • Yes there is, @PavelDonchev - check my answer above..

                  – Agent Shoulder
                  Jan 23 at 17:08















                1














                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.






                share|improve this answer























                • As far as I know - this should be the answer. There is not (to my knowledge) way to get the browser logs natively in Selenium with the C# language. Some of the comments mentioned it may be removed form other language bindings as well. I will be very happy to sew newer information about this but I think the latest one is - you're not going to have it.

                  – Pavel Donchev
                  Dec 28 '18 at 8:01











                • Yes there is, @PavelDonchev - check my answer above..

                  – Agent Shoulder
                  Jan 23 at 17:08













                1












                1








                1







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '15 at 11:39









                Shouvik RoyShouvik Roy

                693




                693












                • As far as I know - this should be the answer. There is not (to my knowledge) way to get the browser logs natively in Selenium with the C# language. Some of the comments mentioned it may be removed form other language bindings as well. I will be very happy to sew newer information about this but I think the latest one is - you're not going to have it.

                  – Pavel Donchev
                  Dec 28 '18 at 8:01











                • Yes there is, @PavelDonchev - check my answer above..

                  – Agent Shoulder
                  Jan 23 at 17:08

















                • As far as I know - this should be the answer. There is not (to my knowledge) way to get the browser logs natively in Selenium with the C# language. Some of the comments mentioned it may be removed form other language bindings as well. I will be very happy to sew newer information about this but I think the latest one is - you're not going to have it.

                  – Pavel Donchev
                  Dec 28 '18 at 8:01











                • Yes there is, @PavelDonchev - check my answer above..

                  – Agent Shoulder
                  Jan 23 at 17:08
















                As far as I know - this should be the answer. There is not (to my knowledge) way to get the browser logs natively in Selenium with the C# language. Some of the comments mentioned it may be removed form other language bindings as well. I will be very happy to sew newer information about this but I think the latest one is - you're not going to have it.

                – Pavel Donchev
                Dec 28 '18 at 8:01





                As far as I know - this should be the answer. There is not (to my knowledge) way to get the browser logs natively in Selenium with the C# language. Some of the comments mentioned it may be removed form other language bindings as well. I will be very happy to sew newer information about this but I think the latest one is - you're not going to have it.

                – Pavel Donchev
                Dec 28 '18 at 8:01













                Yes there is, @PavelDonchev - check my answer above..

                – Agent Shoulder
                Jan 23 at 17:08





                Yes there is, @PavelDonchev - check my answer above..

                – Agent Shoulder
                Jan 23 at 17:08











                0














                driver.manage().logs().get("browser")


                Gets all logs printed on the console. I was able to get all logs except Violations. Please have a look here Chrome Console logs not printing Violations






                share|improve this answer



























                  0














                  driver.manage().logs().get("browser")


                  Gets all logs printed on the console. I was able to get all logs except Violations. Please have a look here Chrome Console logs not printing Violations






                  share|improve this answer

























                    0












                    0








                    0







                    driver.manage().logs().get("browser")


                    Gets all logs printed on the console. I was able to get all logs except Violations. Please have a look here Chrome Console logs not printing Violations






                    share|improve this answer













                    driver.manage().logs().get("browser")


                    Gets all logs printed on the console. I was able to get all logs except Violations. Please have a look here Chrome Console logs not printing Violations







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 5 '18 at 10:58









                    Sangam ShankarSangam Shankar

                    2017




                    2017





















                        0














                        public void Test_DetectMissingFilesToLoadWebpage()

                        try

                        List<LogEntry> logs = driver.Manage().Logs.GetLog(LogType.Browser).ToList();
                        foreach (LogEntry log in logs)

                        while(logs.Count > 0)

                        String logInfo = log.ToString();
                        if (log.Message.Contains("Failed to load resource: the server responded with a status of 404 (Not Found)"))

                        Assert.Fail();

                        else

                        Assert.Pass();




                        catch (NoSuchElementException e)

                        test.Fail(e.StackTrace);




                        You could do something like this in C#. It is a complete test case. Then print the console output as String i.e logInfo in your report. For some reason, Log(log.Message) from the solution above this one gave me build errors.So, I replaced it.






                        share|improve this answer





























                          0














                          public void Test_DetectMissingFilesToLoadWebpage()

                          try

                          List<LogEntry> logs = driver.Manage().Logs.GetLog(LogType.Browser).ToList();
                          foreach (LogEntry log in logs)

                          while(logs.Count > 0)

                          String logInfo = log.ToString();
                          if (log.Message.Contains("Failed to load resource: the server responded with a status of 404 (Not Found)"))

                          Assert.Fail();

                          else

                          Assert.Pass();




                          catch (NoSuchElementException e)

                          test.Fail(e.StackTrace);




                          You could do something like this in C#. It is a complete test case. Then print the console output as String i.e logInfo in your report. For some reason, Log(log.Message) from the solution above this one gave me build errors.So, I replaced it.






                          share|improve this answer



























                            0












                            0








                            0







                            public void Test_DetectMissingFilesToLoadWebpage()

                            try

                            List<LogEntry> logs = driver.Manage().Logs.GetLog(LogType.Browser).ToList();
                            foreach (LogEntry log in logs)

                            while(logs.Count > 0)

                            String logInfo = log.ToString();
                            if (log.Message.Contains("Failed to load resource: the server responded with a status of 404 (Not Found)"))

                            Assert.Fail();

                            else

                            Assert.Pass();




                            catch (NoSuchElementException e)

                            test.Fail(e.StackTrace);




                            You could do something like this in C#. It is a complete test case. Then print the console output as String i.e logInfo in your report. For some reason, Log(log.Message) from the solution above this one gave me build errors.So, I replaced it.






                            share|improve this answer















                            public void Test_DetectMissingFilesToLoadWebpage()

                            try

                            List<LogEntry> logs = driver.Manage().Logs.GetLog(LogType.Browser).ToList();
                            foreach (LogEntry log in logs)

                            while(logs.Count > 0)

                            String logInfo = log.ToString();
                            if (log.Message.Contains("Failed to load resource: the server responded with a status of 404 (Not Found)"))

                            Assert.Fail();

                            else

                            Assert.Pass();




                            catch (NoSuchElementException e)

                            test.Fail(e.StackTrace);




                            You could do something like this in C#. It is a complete test case. Then print the console output as String i.e logInfo in your report. For some reason, Log(log.Message) from the solution above this one gave me build errors.So, I replaced it.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 15 '18 at 19:48

























                            answered Nov 15 '18 at 19:40









                            Raj K LamaRaj K Lama

                            12




                            12



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18261338%2fget-chromes-console-log%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                27

                                Top Tejano songwriter Luis Silva dead of heart attack at 64

                                Category:Rhetoric