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

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

1 thought on “Selenium 4 Features – Retrieving Browser Console Log Using Selenium WebDriver

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.

Selenium 4 Features – Retrieving Browser Console Log Using Selenium WebDriver

by Amod Mahajan time to read: 3 min
1
%d bloggers like this: