SDET Unicorns

Selenium Python Generate Screenshot

Generate Screenshots

Table of Content

In this post, we will take a look at how we can generate a screenshot of a test failure in Selenium Python so that we can quickly look at the screenshot and identify what was the state of our application at that moment.

We will also learn how to take screenshots whenever we want for a certain part of the screen and these screenshots can then be reviewed by your team for manual validation if needed.

Screenshot on failure in Selenium Python (SeleniumBase)

One of the many great features of using the SeleniumBase framework is that it comes with in-built screenshot generation capability when a test fails. Along with the screenshot, it also ends up saving the logs of the test run in the latest_logs/ folder.

Example of the latest_logs/ folder –


In the screenshot above, 3 files got generated when a test failed which are stored under the auto-generated test_name folder –

  • .txt file – failed test logs get stored in this file
  • .html file – a copy of the DOM for that particular page gets stored in this file
  • .png file – screenshot of that particular part of the screen

Generate Screenshot manually

You also have the ability to generate screenshot during the test run at any step using the save_screenshot method –

image 1

save_screenshot method takes in 2 parameters – filename and the folder name. If a folder name is passed in the file will get stored within that folder.

Check out the video below to learn more about generating screenshots using the SeleniumBase framework –

To learn more about Selenium Python, check out the full tutorial series here for free!

I hope this post helped you out, let me know if you have any questions in the comments below!

Happy testing! 

My Resources

Thrive Suite: The all-in-one WordPress theme I used to create my blog.
Jasper AI: My favorite AI writing tool.
Surfer SEO:  A tool to help you rank your content on the first page of Google.

Write Content Faster


Write blog posts that rank for affiliate terms!

Join our mailing list

Unlock the Secrets to Becoming a SDET Pro in the Industry!

Stay ahead of the curve! Join our mailing list for exclusive insights, tips, and the latest industry updates delivered straight to your inbox

Table of Content

Related Post

Functional vs Regression Testing

Functional Testing vs Regression Testing: Main Differences

Testing has increasingly become a requirement in the software development lifecycle in recent years. The realization that development is no longer a focal point for stakeholders but saving costs by catching defects early in their application makes it necessary to learn different testing types.

Read More »