File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
BufferedImage fullImg = ImageIO.read(screenshot);
Point point = e.getLocation();
int eleWidth = e.getSize().getWidth();
int eleHeight = e.getSize().getHeight();
System.out.println(eleWidth);
System.out.println(eleHeight);
BufferedImage eleScreenshot= fullImg.getSubimage(point.getX(), point.getY(), eleWidth,eleHeight);
ImageIO.write(eleScreenshot, "jpg", screenshot);
FileUtils.copyFile(screenshot, new File("D://screenshot.jpg"));
-----------------------------------------------------------------------------------------------------------------------------------------------------
I m using this code to take a screen shot of particular element. but i got an error like:
actually i want to take a screenshot of YT html 5 player "play/pause" button.
--------------------------------------------------------------------------------------------------------------------------------------------------------
Exception in thread "main" java.awt.image.RasterFormatException: (y + height) is outside of Raster
at sun.awt.image.ByteInterleavedRaster.createWritableChild(Unknown Source)
at java.awt.image.BufferedImage.getSubimage(Unknown Source)
at videoPlayer.Videoplayer.main(Videoplayer.java:42)
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Please help me ASAP.
your student :
Avinash kumar