Selenium + Python · Lesson 30 of 43

0/43 done

Module 30: Screenshots

30. Page & Element Screenshots for Failure Diagnosis

15 minlesson

Your task

Implement take_failure_screenshot(driver, save_path):

  1. Call driver.save_screenshot(save_path) and return True.

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

Taking Screenshots in Python

python
# Full viewport screenshot:
driver.save_screenshot("reports/failure_screenshot.png")

# Element-level screenshot (Selenium 4):
card = driver.find_element(By.ID, "pricing-card")
card.screenshot("reports/pricing_card.png")

Key Takeaways & Walkthrough Summary

Visual artifacts are critical when automated tests fail on CI machines. In this lesson, you will master driver.save_screenshot() and element-level screenshots in Selenium 4. Let's capture screenshots!

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

What image formats does save_screenshot support?

PNG is the standard format used by WebDriver for screenshots.

Ready? Solve the task in the editor

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

Python
Skip