How to Take Screenshot and Partial Screenshot in Selenium WebDriver

In this tutorial we will learn to take full screenshot and partial screenshot. In automation we capture the screenshots for reference. To capture screenshot in Selenium 'TakeScreenshot' interface is used.

Take Screenshot Command:

 * Capture Screenshot               *

/* Create object of File class of Java 
 * And capture screenshot using getScreenshotAs() method of Webdriver
 * Set Output type of screenshot taken as 'File'
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

/* Use FileUtils class of Java 
 * Call it's copyFile method
 * Copy screenshot file to a location with some name and extension you want
FileUtils.copyFile(screenshot, new File("D:\\screenshot.jpg"));

How to Take Partial Screenshot:

Sometimes we don't want to take screenshot of the full screen. Reasons might be, full size images would last in huge memory storage for image directory or sometimes we need to take element specific screenshot due to test case requirement which makes more sense.

Here is the Webdriver code snippet for taking partial screenshot:

Happy Learning!

Handle Dynamic Xpaths  << Previous   ||   Next >>   How to Upload File (Robot Class)

Refer Selenium Webdriver Tutorials Series

Join Telegram channel at
Feel free to ask queries or share your thoughts in comments or email me.

Follow Us

Quora Space | Facebook Page | Telegram Channel
Feel free to ask queries or share your thoughts in comments or email us.


  1. I appreciate your efforts for creating these quick reference blogs. Keep up the good work.
    Just an observation that TakeScreenshot is an Interface and not a Class.


Post a Comment

Popular posts from this blog

10 Best Demo Websites for Automation Testing Practice

Automate E-Commerce Website using Selenium Webdriver

Automate Browser Actions on using Selenium

Automate Amazon Website 'Menu links' using Selenium