Reputation: 1601
This is a follow-up to the Counting the number of HTML elements having same attribute in Watir question.
So, suppose I have a HTML element as follows
<input type="password" class="foo" />
<span class="foo"></span>
<a href='1' class="foo">Text</a>
So, I can obtain a collection of all the elements having the same class name by using
elements = browser.elements(:class,"foo")
Since, its an collection, I can use the each method to iterate over the collection. While iterating over the collection, I want to determine what type of tag is represented? (Something similar to the nodeName or the tagName method in Javascript). Is there a way we could do this in Watir?
Sample code would be :
elements = browser.elements(:class,"foo")
elements.each { |element|
puts element.<Watir_method_similar_to_nodeName_of_JavaScript>
}
Upvotes: 4
Views: 1203
Reputation: 57312
elements.each {|element| puts element.tag_name}
Output:
input
span
a
Upvotes: 3