Selenium + Python · Lesson 42 of 43

0/43 done

Module 42: Selenium Debugging

42. Debugging Playbook: DevTools, Browser Logs & Breakpoints

16 minlesson

Your task

Implement format_console_log(level, message):

  1. Return f"[{level}] {message}".

Write it in the editor, then press Check answer (Ctrl + Enter).

Debugging Techniques in Python

  1. Interactive Debugger: Add breakpoint() directly inside your test code to drop into an interactive PDB session while the browser remains open.
  2. Retrieve Browser Logs:
python
for entry in driver.get_log("browser"):
    if entry["level"] == "SEVERE":
        print(f"Browser Console Error: {entry['message']}")

Key Takeaways & Walkthrough Summary

When an automated test fails unexpectedly, diagnosing it quickly saves countless hours. In this lesson, you will master reading browser console logs, using Python's built-in breakpoint(), and inspecting dynamic elements. Let's master debugging!

Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

How do I pause execution to inspect the DOM manually?

Calling breakpoint() halts Python execution and gives you an interactive shell where you can query driver.page_source or inspect the open browser window.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip