views:

62

answers:

1

So here is a little challenge. I have an image. It has 2 attributes:

  1. a random ID - not helpful
  2. an image url - but it is a button, and other buttons use the same image url, not helpful
  3. a CSS class - also used by too many other things to be helpful
  4. a style - neither helpful nor unique

This image is however inside of an anchor tag, but the anchor tab isn't to a page, it just runs some javascript. Bellow is the html in question:

<a id="template:j_id__ctru168pc2" 
title="Click for the Manual Class LOV" class="xei" style="text-decoration: none;"
onclick="return false;" href="#">
    <img id="template:j_id__ctru169pc2" class="xgs" 
    style="border: 0pt none;" src="images/lov_ena.png">
</a>

How can I click this image without using the ID?

+5  A: 
selenium.click("//a[@title='Click for the Manual Class LOV']/img");
Dave Hunt
@Zombies, Google for XML Xpath Tutorial and stuff like this will popup http://www.w3schools.com/xpath/xpath_intro.asp
David Andersson
Good one, Dave.
Tony Ennis