I'm a bit stuck with getting a grandparent element by Xpath. Unfortunately, my tries were unsuccessful.
HTML
<span class="fsm fwn fcg">
<a href="bla bla">
<abbr>
<span class="timestampContent" id="js_19">21 mins</span>
</abbr>
</a>
</span>
i need to get the <a href="bla bla"> element as the grandparent for <span class="timestampContent" id="js_19">21 mins</span>
i tried something like the following:
//span[@class='timestampContent' and contains(text(), 21 mins)]../.. or
../..//span[@class='timestampContent' and contains(text(), 21 mins)]
and some other options, but it didn't work as I expected.
Your first try is close, only a / before .. was missing (and missing quotes around '21 mins', which I believe was just a typo) :
//span[@class='timestampContent' and contains(text(), '21 mins')]/../..
Alternatively, you can do it the other way around i.e by selecting element that has grand child span of certain criteria :
//*[*/span[@class='timestampContent' and contains(text(), '21 mins')]]
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