Challenge - 5 Problems
Network Log Capture 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 network log capture code?
Consider the following Python Selenium code snippet that captures network logs using Chrome DevTools Protocol (CDP). What will be printed by the last print statement?
Selenium Python
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.desired_capabilities import DesiredCapabilities options = Options() options.add_argument('--headless=new') caps = DesiredCapabilities.CHROME.copy() caps['goog:loggingPrefs'] = {'performance': 'ALL'} service = Service() driver = webdriver.Chrome(service=service, options=options, desired_capabilities=caps) driver.get('https://example.com') logs = driver.get_log('performance') count = 0 for entry in logs: message = entry['message'] if 'Network.responseReceived' in message: count += 1 print(count) driver.quit()
Attempts:
2 left
💡 Hint
Check how performance logging is enabled and what keys exist in the log entries.
✗ Incorrect
The code enables performance logging via DesiredCapabilities and captures network events. Each log entry has a 'message' key containing JSON strings. Filtering for 'Network.responseReceived' counts network responses. This count is printed as a positive integer.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies a network request URL in Selenium logs?
You have captured performance logs in Selenium and want to assert that a request to 'https://api.example.com/data' was made. Which assertion code snippet correctly checks this?
Selenium Python
logs = driver.get_log('performance') urls = [] for entry in logs: message = json.loads(entry['message'])['message'] if message['method'] == 'Network.requestWillBeSent': urls.append(message['params']['request']['url'])
Attempts:
2 left
💡 Hint
Check how to verify if at least one URL matches the target string.
✗ Incorrect
Option A uses any() to check if the target URL is contained in any captured URL, which is correct. Option A checks exact membership which may fail if URLs have query parameters. Option A requires all URLs to match exactly, which is wrong. Option A raises ValueError if URL not found.
🔧 Debug
advanced2:30remaining
Why does this Selenium network log capture code raise a JSONDecodeError?
This code snippet tries to parse network logs but raises json.decoder.JSONDecodeError. Identify the cause.
Selenium Python
import json logs = driver.get_log('performance') for entry in logs: message = json.loads(entry['message']) print(message['message']['method'])
Attempts:
2 left
💡 Hint
Check the structure of the 'message' field in performance logs.
✗ Incorrect
The 'message' field is a JSON string that contains another JSON string inside the 'message' key. The code parses only once, so message['message'] is still a string, not a dict. Accessing ['method'] on a string causes JSONDecodeError or TypeError.
❓ framework
advanced2:30remaining
Which Selenium WebDriver setup correctly enables network log capture with Chrome in Python?
Select the code snippet that correctly configures Chrome WebDriver to capture network logs using performance logging.
Attempts:
2 left
💡 Hint
Check how to enable performance logging via DesiredCapabilities.
✗ Incorrect
Option C correctly sets 'goog:loggingPrefs' in DesiredCapabilities and passes it to ChromeDriver. Option C tries to set capability on Options, which is invalid. Option C enables network via CDP but does not enable performance logs. Option C adds a logging argument but does not enable performance logs.
🧠 Conceptual
expert3:00remaining
What is the main limitation of capturing network logs via Selenium's performance logging?
Choose the most accurate statement about the limitations of using Selenium's performance logging to capture network traffic.
Attempts:
2 left
💡 Hint
Consider what data Selenium's performance logs provide compared to specialized network tools.
✗ Incorrect
Selenium's performance logging captures many network events but may miss some due to buffering and does not provide full HAR data. It does not capture raw TCP packets nor disables caching by default.