Challenge - 5 Problems
Browser Console Log Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Python code snippet capturing browser console logs?
Consider the following Selenium Python code that opens a page and captures browser console logs. What will be printed?
Selenium Python
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By options = webdriver.ChromeOptions() options.set_capability('goog:loggingPrefs', {'browser': 'ALL'}) service = Service() driver = webdriver.Chrome(service=service, options=options) driver.get('data:text/html,<script>console.log("Test log");console.error("Error log");</script>') logs = driver.get_log('browser') for entry in logs: print(entry['level'], entry['message']) driver.quit()
Attempts:
2 left
💡 Hint
Browser console logs include levels like INFO and SEVERE for logs and errors respectively.
✗ Incorrect
The console.log message appears with level INFO, and console.error appears with level SEVERE in Selenium browser logs.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies that a browser console log contains an error message?
You have captured browser logs in a variable named logs (a list of dicts). Which assertion correctly checks that at least one log entry contains the text 'TypeError'?
Selenium Python
logs = [{'level': 'SEVERE', 'message': 'Uncaught TypeError: undefined is not a function'}, {'level': 'INFO', 'message': 'Page loaded'}]Attempts:
2 left
💡 Hint
You need to check inside each log message string, not the list or dict keys directly.
✗ Incorrect
Option B correctly uses a generator expression to check if any log message contains 'TypeError'. Other options are invalid syntax or incorrect logic.
❓ locator
advanced1:30remaining
Which locator strategy is best to find the browser console log entries in Selenium Python?
You want to capture browser console logs using Selenium Python. Which method and argument correctly retrieves these logs?
Attempts:
2 left
💡 Hint
Selenium WebDriver has a method to get logs by specifying the log type as a string.
✗ Incorrect
The correct method is get_log with argument 'browser'. Other options are either invalid or do not exist.
🔧 Debug
advanced2:00remaining
Why does this Selenium Python code fail to capture browser console logs?
Given this code snippet, why does logs = driver.get_log('browser') return an empty list?
Selenium Python
from selenium import webdriver options = webdriver.ChromeOptions() driver = webdriver.Chrome(options=options) driver.get('https://example.com') logs = driver.get_log('browser') print(logs) driver.quit()
Attempts:
2 left
💡 Hint
You must enable logging preferences explicitly in ChromeOptions to capture logs.
✗ Incorrect
Without setting 'goog:loggingPrefs' capability in ChromeOptions, browser logs are not collected.
❓ framework
expert3:00remaining
How to integrate browser console log capture into a pytest Selenium test with assertion?
You want to write a pytest test that opens a page, captures browser console logs, and asserts no errors are present. Which code snippet correctly implements this?
Attempts:
2 left
💡 Hint
Filter logs by level 'SEVERE' and assert the list is empty for no errors.
✗ Incorrect
Option A correctly filters logs by level and asserts no severe errors exist. Others either use wrong log type, wrong assertion, or incorrect logic.