3

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?

Community
  • 1
  • 1
pdcoxhead
  • 383
  • 5
  • 11
  • Possible duplicate: http://stackoverflow.com/questions/10848900/how-to-take-partial-screenshot-frame-with-selenium-webdriver/10849914 – Franz Ebner Oct 15 '13 at 05:50
  • Unless you specifically need to see the image in context, it might be simpler to use Selenium to grab the image URL, then [download it directly](http://stackoverflow.com/questions/5882005/how-to-download-image-from-any-web-page-in-java). – rutter Oct 15 '13 at 08:46
  • @FranzEbner It's not easy finding your first stack overflow question that hasn't been asked before. That is effectively the way I ended up going but I was curious to see if anyone else had found a way to check the individual image. Thanks – pdcoxhead Oct 16 '13 at 00:23
  • @rutter Sounds like that should work, you could just navigate to the URL and capture the screenshot from that. Thanks – pdcoxhead Oct 16 '13 at 00:26
  • @pdcoxhead you're talking about a screen capture on a WebElement... You can't save a button by image URL for instance. – Franz Ebner Oct 16 '13 at 06:06

1 Answers1

1

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

Pazonec
  • 1,549
  • 1
  • 11
  • 35
  • Worked a way around this ages ago by knowing where the item was on the screen and grabbing the pixel values from the position in the page screen shot. Thanks for the tip though, I'll try it out some time. – pdcoxhead Oct 01 '14 at 01:55