I'd like to search for text within the html then select the parent of the element so I can use that to store a reference ID as a string. (I'm using watir to do this as the purpose for it is automated testing)
so here's an example:
<html>
<body>
<div id="container">
<span class="story">
<span>
ref4040
</span>
</span>
<div id="text">
example
</div>
</div>
</body>
</html>
Is there a way I can use ruby to search for the text "example" then select the parent so I can store the reference ID within the span as a string?
(I know you can do it the simple way in this example of selecting the div then the span, but on the project I am actually working on, this is not possible. The only possible way of doing it is via search for the text then selecting the reference.)
You can get the parent element by doing .parent
.
So you could do something like:
browser.div(:text, 'example').parent.span(:class, 'story').text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With