Watir Hint for Working with ImageButtons

Dustin, one of my co-workers, ran into a problem accessing the "alt" attribute on image buttons using Watir and discovered a useful trick:

Who knows if this will ever be useful to anyone else, but I've been trying to work with imageButtons, which have alt tags. In HTML they render as <input type="image".../> I wanted to access the alt tag of the image. ie.contains_text wouldn't find it for me. Only image objects in watir have any knowledge of alt tags.  And unfortunately, watir recognizes imageButtons, not as images, but as buttons.
there is almost no documentation that covers this, but I found that even though these are buttons, you can use image methods to manipulate these 'buttons'. For example, you can get the object with:
  • button = $ie.button(:alt, "This is the alt text...") *alt is only exposed for images, but works for imageButtons.
And you can manipulate the buttons with image methods, such as:
  • button.exists?

1 Comment

Comments have been disabled for this content.