开发者

How to determine what type of a HTML element is selected in Watir

开发者 https://www.devze.com 2023-03-15 22:22 出处:网络
This is a follow-up to the Counting the number of HTML elements having same attribute in Watir question.

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_sim开发者_JS百科ilar_to_nodeName_of_JavaScript>
}


elements.each {|element| puts element.tag_name}

Output:

input
span
a
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号