Get full length Screenshot using Robot class in Selenium

You must be having the question in your mind that why we need to take Screenshot using Robot class. I know everyone is aware of taking the screenshot using Selenium API but want to tell you that we have some limitation of this.

If you have  not gone through screenshot part then below post will help you.

How to capture screenshot in Selenium

How to capture screenshot only on failures.


Limitation of screenshots by Selenium.

1- When any alert comes on screen and if you call screenshot method then it will fail because the alert is windows activity.

If you are not aware of Alert in Selenium and how to handle then check out below article to get more info.

How to handle Alert in Selenium webdriver


2- When running cross browser testing if need to verify that test is running on which browser then you won’t be able to verify because it capture only web view part.

Check out below post if you have not done any cross-browser testing yet.

How to perform cross browser testing in Selenium


Point to Screenshot using Robot class

1- We need to take help of Rectangle class and some other packages of AWT package.

import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;


2- I will suggest using this method only when you are unable to take screenshots using normal screenshot approach.


Program Screenshot using Robot class


After execution of above code you will get screenshot like below

Screenshot using Robot class

Screenshot using Robot class


You can also create the Utility class for this and start calling based on  need. Hope you have enjoyed this article.

Please let me know your thoughts on this.




  1. Rohit
  2. Neeraj Kumar
  3. ashok
  4. ashok
  5. uppuluri Ramesh
  6. Biswa bhusan Mishra