Check if image is displayed with selenium ?

  • 1 Replies
  • 925 Views
Check if image is displayed with selenium ?
« on: June 02, 2016, 10:26:55 am »
I have a website to test with various image galleries

I'm trying to check if my page has images displayed - that they contain valid image data.

Can it be done with selenium ?

Re: Check if image is displayed with selenium ?
« Reply #1 on: June 06, 2016, 19:27:03 pm »
A solution I used a while back:

check if image is displayed with JS executor

Code
Object result = ((JavascriptExecutor) driver).executeScript(
   "return arguments[0].complete && "+
   "typeof arguments[0].naturalWidth != \"undefined\" && "+
   "arguments[0].naturalWidth > 0", imageElement);

    boolean loaded = false;
    if (result instanceof Boolean) {
      loaded = (Boolean) result;
      System.out.println(loaded);
    }

 

Sitemap 1 2 3 4 5 6 7 8