Capturing screenshot using java.awt.Robot class-Selenium WebDriver



The java.awt.Robot class is mainly useful to perform native actions where keyword and mouse actions to be performed. This actions are helpful for automation. If the current platform configuration does not allow input controls, an AWTException will be thrown when using the java.awt.Robot class. In this post we will java.util.Robot class for capturing the screenshots. The method createScreenCapture(Rectangle screenRect) is available in java.awt.Robot class which helps to create an image containing pixels read from the screen.The java.awt.Rectangle object to be passed as an parameter for capturing the screenshot. To create an Rectangle object the java.awt.Dimension[Height*Width] object to be passed as an parameter.

API Classes and Methods useful to capture the Screenshot as follows:

  • Robot Class Object
  • Rectangle Class Object
  • Dimension Class Object- Input Parameters Height * Width

Selenium WebDriver Code

Output:

The full screen is captured as screenshot which is the expected outcome as shown below:

Capture Screenshot using java.awt.Robot Class

Capture Screenshot using java.awt.Robot Class

Leave a Reply

Your email address will not be published. Required fields are marked *