Archive for the ‘code’ tag
Watir: Select Element Using Multiple Attributes
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:
browser.div(:name => 'foo', :index => 2).clickThis will find the second div with the name ‘foo’.
And it really works.
browser.link(:text => "reply", :index => 2).href
=> "{site}2"
Watir: Select Element Using HTML
Bret Pettichord posted this at wtr-general few days ago.
If you have a link that looks like this:
<a href="#" onclick="new Ajax.Request('/data_entry/ajax_add_term/131?contract_id=227', {asynchronous:true, evalScripts:true}); return false;">add a term</a>
you can click it using:
browser.link(:html, /contract_id=227/).click
Watir: Select Element Using Custom Attribute
Paul Rogers and Prema Arya just started a very interesting thread at wtr-general.
If you have text field
<input custom_attribute="so cool" type="text" />
you can get value of custom_attribute
browser.text_field(:index, 1).attribute_value("custom_attribute")
#=> "so cool"
and you can set value of that text field using custom_attribute
browser.text_field(:xpath , "//input[@custom_attribute='so cool']/").set("even more cool")
