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.
browser.link(:text, "reply").href
#=> "{site}1"
I can use :index
, but if anything on that page changes, it could break.
browser.link(:index, 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:This will find the second browser.div(:name => 'foo', :index => 2).click
div
with thename
foo
.
And it really works.
browser.link(:text => "reply", :index => 2).href
#=> "{site}2"