Vishal
Vishal

Reputation: 11

Selenium - How to match image presence and location on page

My query is that - I have my images on webpage- a logo or say navigation bar i can store as an image. Can i test using selenium presence of these images on a webpage when loaded along with the position of the image on page. What my issue is that i need to actually look at image objects in HTML and also may be images not in HTML but they are partial screenshots of webpage which i want to match. This test will help me pick alignment issues - in case my navigation bar is now going to second row i can match with previous stored image to check.

Thanks VB

Upvotes: 1

Views: 8362

Answers (2)

Panacea
Panacea

Reputation: 247

An example on how to check if a particular image is present:

In this page:http://www.google.ie/firefox?client=firefox-a&rls=org.mozilla:en-US:official

Selenese command

Command: verifyElementPresent
Target: //td/table/tbody/tr/td/table/tbody/tr/td/img[@src='/images/firefox/Fx4Launch.png']

Hint: If you want help to get the XPath for a particular element I recommend you using a plugin like Firebug (http://getfirebug.com/)

Put an extra "\" in the beginning of the xpath copied by Firebug, otherwise selenium do not find the element.

Upvotes: 1

Feanor
Feanor

Reputation: 2725

You can verify that an image is at a location like so:

verifyElementPresent //div/p/img

This example uses XPath to locate an <img> element that follows a <div> and <p> tag.

But verifying that a screenshot is the same as the rendered page? You're talking about a completely different problem, which is image recognition. Selenium is a tool for automated acceptance testing.

Upvotes: 0

Related Questions