Capture Screenshot in Selenium WebDriver using FileHandler Class

Are you wondering why FileUtils is not working to capture screenshot. Is your eclipse not showing any suggestion when you hover on FileUtils. Don’t worry. Its an update in Selenium. In the latest version of Selenium, FileHandler class is implemented to capture screenshot instead of FileUtils.

Here is a sample program to use FileHandler in a Selenium script to capture a screenshot.

Given a detailed explanation inside the program for your understanding.

We have to import package “” to work with FileHandler class

Here is a sample program.

Before Selenium 3.6.0, Apache Commons Library comes along with Selenium. But in Selenium new versions from Selenium 3.6.0 onwards, we have to download it separately to use it in our project.

You can download it from

If you are using Maven Project, here is the dependency of Apache Commons Library

If you have any queries, please comment below.

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

Leave a Comment

Share via
Copy link
Powered by Social Snap