Željko Filipin's blog.
Home Blog Tags Now License

View on GitHub
6 February 2007

Watir: Select Element Using Multiple Attributes

by Željko Filipin

There are two links in a page that I am testing.

<a href="1">reply</a>
<a href="2">reply</a>

I need to get value of href attribute for the second link.

I can not use :text, because it will return href attribute for the first link., "reply").href
#=> "{site}1"

I can use :index, but if anything on that page changes, it could break., 2).href
#=> "{site}2"

Bret Pettichord posted posted a solution for this at wtr-general a few months ago.

In 1.5, this syntax works:
browser.div(:name => 'foo', :index => 2).click
This will find the second div with the name foo.

And it really works. => "reply", :index => 2).href
#=> "{site}2"
tags: code - ruby