Search code examples
javaimageseleniumscreenshotpixel

Can you convert a Selenium WebElement into a byte array or image object (using Java)?


I would like to validate an image generated by the web server I am developing. I want to check the image layering is correct by finding out what colour a particular pixel in the image is. The image is contained by an with the background-image attribute set to a URL that returns that image. I have seen several mentions of using a screen capture to get the actual image but I wondered if there is a way to get only the image rather than the entire web page.

Can you:

  1. do a screen capture on a WebElement

  2. extract the bytes the image comprises of

    or is there some other way?


Solution

  • Try aShot Util it allows to take screenshot of webelement and convert it to byte array.