How to get an element using inner text (Watir, Nokogir, Hpricot)

Posted by Hpriguy on Stack Overflow See other posts from Stack Overflow or by Hpriguy
Published on 2010-02-13T21:03:28Z Indexed on 2010/03/30 22:03 UTC
Read the original article Hit count: 469

Filed under:
|

I have been expeirmenting with Watir, Nokogir and Hpricot. All of these use top->down approach which is my problem. i.e. they use element type to search element. I want to find out the element using the text without knowing element type. e.g.

<element1> 
    <element2> Text2 </element2>
    <element3> Text3 </element3>
     text4
</element1>

I want is to get element2 and element1 etc by searching for Text2 and Text3.

Please note that I do not know if elements are divs or tr/tds or links etc. I just know the text. Algorithem should be something like : iterated through all the elements, match inner text, if match get me the element and the parent element.

Let me kow if this is possible in any way?

© Stack Overflow or respective owner

Related posts about hpricot

Related posts about watir