[Wtr-general] Access objects by html tag and index
Nate
forum-watir-users at openqa.org
Mon Oct 9 10:20:25 EDT 2006
I've written a method to allow idenfitication by tags other than the default :name :id, and also index objects based on a specific tag, not just a single index.
The code is at the bottom of this message.
For example, if I want to click on a link that has the word Edit in it's html properties I'd use the following :
ie.findElement(:links, :html, /Edit/).click
If I wanted to click on the second checkbox called "ToggleAll", I'd use the following:
ie.findElement(:checkboxes, :name, "ToggleAll", 2).click
I've found this is a good solution when there are multiple objects that share similar properties and when the only differentiating properties are in the .html attribute of the objects...
class IE
def findElement(elementType, type, searchText, index=1)
elements = self.send(elementType)
count = 0
for i in 1..elements.length
if (elements[i].send(type).match(searchText) != nil)
count += 1
end
if (count == index)
return elements[i]
end
end
return nil
end
end
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=4711&messageID=13020#13020
More information about the Wtr-general
mailing list