Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Selenium 4 Features – Retrieving Browser Console Log Using Selenium WebDriver

Posted on 03/16/2025 By admin

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:-

package Selenium4Features; import java.awt.AWTException;
import java.util.List; 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 io.github.bonigarcia.wdm.WebDriverManager; public class ConsoleLog { public static void main(String[] args) throws AWTException { // Setting chrome executable WebDriverManager.chromedriver().setup(); // Launching browser WebDriver driver = new ChromeDriver(); // Loading URL driver.get("http://makeseleniumeasy.com/"); // Mentioning type of Log LogEntries entry = driver.manage().logs().get(LogType.BROWSER); // Retrieving all log List logs= entry.getAll(); // Print one by one for(LogEntry e: logs) { System.out.println(e); } // Printing details separately for(LogEntry e: logs) { System.out.println("Message is: " +e.getMessage()); System.out.println("Level is: " +e.getLevel()); } } } 

Output:-

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 78.0.3904.105 (60e2d8774a8151efa6a00b1f358371b1e0e07ee2-refs/branch-heads/3904@{#877}) on port 22084
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1576137115.752][WARNING]: Timed out connecting to Chrome, retrying...
Dec 12, 2019 1:21:57 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[2019-12-12T13:21:59+0530] [SEVERE] http://makeseleniumeasy.com/wp-content/plugins/email-subscribe/js/subscribe-popup.js?ver=5.1.3 1101:20 Uncaught TypeError: Cannot read property 'css' of undefined
[2019-12-12T13:21:59+0530] [SEVERE] http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js 42:397 Uncaught N: adsbygoogle.push() error: Fluid responsive ads must be at least 250px wide: availableWidth=220
Message is: http://makeseleniumeasy.com/wp-content/plugins/email-subscribe/js/subscribe-popup.js?ver=5.1.3 1101:20 Uncaught TypeError: Cannot read property 'css' of undefined
Level is: SEVERE
Message is: http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js 42:397 Uncaught N: adsbygoogle.push() error: Fluid responsive ads must be at least 250px wide: availableWidth=220
Level is: SEVERE

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

#HappyLearning

Uncategorized

Post navigation

Previous Post: string
Next Post: Postman Tutorial Part 8 – How to Send PUT Request in Postman

Related Posts

Skipped1 – Make Selenium Easy Uncategorized
TestNG Tutorials 40: Groups of Groups or MetaGroups in TestNG Uncategorized
REST Assured Tutorial 45 – Fetch Value From Nested JSON Object Using JsonNode – Jackson – at() Method Uncategorized
Frequently Asked Java Program 03: Java Program to check if any string is palindrome Using inbuilt Reverse method of Java Uncategorized
rolling file appender in log4j2 Uncategorized
Override – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark