How can I access the second element with the same attributes using Watir?
-
13-09-2019 - |
Question
I have a page with HTML like this:
<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"
Solution
browser.link(:text => "reply", :index => 1).href
=> "{site}2"
Sources:
- http://wiki.openqa.org/display/WTR/Multiple+Attributes
- http://wiki.openqa.org/display/WTR/How+and+What
- http://wiki.openqa.org/display/WTR/Ways+Available+To+Identify+HTML+Tag
- http://wiki.openqa.org/display/WTR/Methods+Supported+by+Element
- http://rubyforge.org/pipermail/wtr-general/2006-November/008001.html
- http://zeljkofilipin.com/2007/02/06/watir-select-element-using-multiple-attributes/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow