1

There is a page with a large number of images. The images are set as a CSS style background looking like this:

<div style="background-image: url(&quot;http://test.com/abc123.jpg&quot;);">

The page loads, but sometimes, some images are not loaded. The URL is still set, the DIV has the correct size, only the image itself is not displayed. (This may be due to a browser, server or a network problem but that is not important here - we only want to know whether the image is loaded or not).

How can I check that a background image like this has been loaded?

Peter S.
  • 173
  • 1
  • 1
  • 10
  • You'd have to implement a proxy. You'd have to check what exactly is returned from the `GET` request of that image: http://jimevansmusic.blogspot.co.uk/2013/08/implementing-webdriver-http-status.html ... – Arran Nov 11 '13 at 09:40
  • If for any reason, proxy can be implemented, that you can use Sikuli to validate the image. Refer the Sikuli.org site or if you are using Java you can check this link directly - http://doc.sikuli.org/faq/030-java-dev.html – Akbar Nov 11 '13 at 11:50
  • I'll keep Sikuli in mind for later. Is there really no way to get around this besides using another test library or setting up a proxy? – Peter S. Nov 11 '13 at 14:06
  • (This is data available for the browser, mind you - e.g. if you mouseover the image URL in Firebug under HTML/Styles, you do get the information that the URL could not be loaded. The question is only how can one get this information into Selenium...) – Peter S. Nov 11 '13 at 14:17
  • I tried what was suggested here http://stackoverflow.com/questions/11049344/can-i-use-console-alert-some-other-means-to-read-out-all-css-properties-at-once and here: http://stackoverflow.com/questions/85992/how-do-i-enumerate-the-properties-of-a-javascript-object ...to no avail. It's odd that there doesn't seem to be a (simple) solution to what has to be a common problem. – Peter S. Nov 13 '13 at 09:35

1 Answers1

0

You could get browser log and analyze it for errors https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/log

Or you could inject some js that will validate such elements https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/execute

I could not find a way to detect loading of background image, but you could inject hidden img and bind on its 'load' event. But its not very reliable between browsers, see http://api.jquery.com/load-event/

senz
  • 1,980
  • 1
  • 16
  • 14