Make Selenium Easy

Selenium 4 Features – Retrieving Browser Console Log Using Selenium WebDriver

Selenium 4 is out ( Alpha version at the time of writing this post). They have given a very important feature in Selenium 4 which is Logging. Logging is generally helpful to know what went wrong.

When you launch a website in browser, you can see logs in console tab of Developer tool. These logs are important to find bugs which may be missed by manual testers or automation tests. Red color logs are Errors while yellow colored logs are Warnings.

Now it is possible to capture these logs using Selenium and we can analyse these logs to find missed bugs. Developers will also get a better idea from these logs. This log type is called Browser level.

Selenium WebDriver is providing five log types as of now:-

  1. Browser:- Javascript console logs from the browser
  2. Client :- Logs from the client side implementation of the WebDriver protocol (e.g. the Java bindings)
  3. Driver:- Logs from the internals of the driver (e.g. FirefoxDriver internals)
  4. Performance :- Logs relating to the performance characteristics of the page under test (e.g. resource load timings)
  5. Server :- Logs from within the selenium server.

In this example we are focusing on Browser level Log type. Below are some important points:-

  • LogType is a class which provides you static final constants such as to pass log type.
  • LogEntries is a class which is iterable which consists log details.
  • Option inner interface of WebDriver interface consists “logs()” methods. We can access it using driver.manage().logs()

Program:-

Output:-

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

5 thoughts on “Selenium 4 Features – Retrieving Browser Console Log Using Selenium WebDriver

  1. Hi, the above thing doesn’t works if I use RemoteDriver, I need to execute my scripts in remote machine and is there any way to get console errors

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.