0
0
Selenium Pythontesting~5 mins

Why evidence collection supports debugging in Selenium Python

Choose your learning style9 modes available
Introduction
Collecting evidence like screenshots and logs helps find and fix problems by showing what happened during a test.
When a test fails and you want to see what the screen looked like at the failure moment.
When you want to keep a record of test steps to understand the flow later.
When debugging intermittent errors that do not happen every time.
When sharing test results with teammates to explain issues clearly.
When tracking down why a web page did not load or behave as expected.
Syntax
Selenium Python
driver.save_screenshot('filename.png')
# or
logs = driver.get_log('browser')
Use save_screenshot to capture the current browser view as an image file.
Use get_log to collect browser console messages for debugging.
Examples
Takes a screenshot and saves it as 'error.png' in the current folder.
Selenium Python
driver.save_screenshot('error.png')
Retrieves browser console logs and prints each log entry.
Selenium Python
logs = driver.get_log('browser')
for entry in logs:
    print(entry)
Sample Program
This script opens a webpage, takes a screenshot, collects browser logs, prints them, and then closes the browser.
Selenium Python
from selenium import webdriver

# Start browser
driver = webdriver.Chrome()

# Open a page
driver.get('https://example.com')

# Take screenshot
screenshot_file = 'example_page.png'
driver.save_screenshot(screenshot_file)

# Get browser logs
logs = driver.get_log('browser')

# Print logs
for entry in logs:
    print(entry)

# Close browser
driver.quit()
OutputSuccess
Important Notes
Screenshots show exactly what the user would see, making it easier to spot visual issues.
Browser logs can reveal JavaScript errors or warnings that affect page behavior.
Collecting evidence during tests helps save time by avoiding guesswork.
Summary
Evidence collection captures what happened during tests.
Screenshots and logs are common types of evidence.
This helps quickly find and fix problems.