how to take a screenshot of your Selenium test with Python

tonetheman profile image Tony Colston ・1 min read

One thing you will want to do is save a screenshot from your Selenium test. You can use the image as an artifact to prove a test is passing or failing. An image of your test can also prove useful for debugging things visually.

from selenium import webdriver

driver = None
    cpath = "e:\\projects\\sel\\chromedriver.exe" # note 1
    driver = webdriver.Chrome(cpath)
    driver.save_screenshot("google.png") # note 2
    if driver is not None:

Note 1 - I have my chromedriver.exe in the directory "e:\projects\sel", you will need to change this value to match where chromedriver.exe is located on disk.

Note 2 - This is the line where the image is generated. The name of the image is passed to the function in this case I named the image "google.png." You can choose any name you like.

The image format used is PNG (portable network graphics) https://en.wikipedia.org/wiki/Portable_Network_Graphics

The one thing to note that this picture will be "above the fold" and not a full page image.

Posted on by:

tonetheman profile

Tony Colston


wanna be gamedev ... all around nerd and dev


Editor guide