I have this HTMLcode:
<div class="A">
<div class="B">
Text1
</div>
</div>
<div class="A">
<div class="B">
Text2
</div>
</div>
So i need to find index of div class=’A’ where i find some text. I use Watir Webdriver and now i have this code:
if @ff.div(:class=>'A').div(:text=>'Text1')
then ind=@ff.div(:class=>'A').index
end
but of course this doesn’t work saying ‘undefined local variable or method `index”.
There’s no way to get the index using the webdriver since they are relative to the collection of matched elements. What you can try to do is collect the elemetns text as Array and then get the index of the target text.
Note that this will only work for simple scenarios (like your example). If you need to attack a more complex case update your example to match the real scenario.