Search code examples
xpathwatirwatir-webdriver

Watir : recognizing image button


I am trying to get a repetitive task done using Watir and I am having difficulties, need your help with it. I have the below code for the button:

<button class="ppm_button " onclick="submitForm('page','more=1');" type="button">
  <img border="0" align="absmiddle" title="Add and Select More" alt="Add and Select More" style="width: 11px; height: 8px; background: url("ui/uitk/images/nde.png") no-repeat scroll 0px 0px transparent;" src="ui/uitk/images/s.gif" >
  &nbsp;Add and Select More
</button>

I try to get the xpath using firebug and use the same xpath to run the script on ff, it fails. I am having hard time giving an appropriate xpath to recognize the object.

Any help will be greatly appreciated.


Solution

  • You should be able to get this avoiding xpath.

    Try using a Watir selector like:

    b.img(:src => "ui/uitk/images/s.gif")
    

    You should then be able to append whatever you want to do with the element on to the end e.g. .click

    This is going off of the available properties at https://github.com/watir/watir/wiki/HTML-Elements-Supported-by-Watir but I'm not sure what version of Watir you're using, or how up to date that list is.

    According to it you could also use:

    b.img(:alt => "Add and Select More")