0

So I'm trying to get the span node in the html below using xpath, and the only things I want to be used in the xpath are the text node "follower" and the span node itself, not any other nodes.

<li class="-nal3 ">
    <span class="g47SY ">1</span> 
    follower
</li>

In other words, all the information we have is that, there is a text node in our html indicating "follower" and its preceding sibling is a span node. That's all we know. and we want to get an attribute of that span node.

I tried a lot of things but none of them seems to work! I searched a lot but couldn't find anything on how to use those text nodes in xpath, let aside finding other nodes using these nodes haha. Would appreciate if anyone can help. (I'm actually using Rselenium to to the job btw)

Farzad
  • 13
  • 4
  • this may help https://stackoverflow.com/questions/6520192/how-to-get-the-text-node-of-an-element – Dev Dec 02 '18 at 11:01

1 Answers1

0

This will return you the <span> node:

//text()[contains(., 'follower')]/preceding-sibling::span

And this too:

//*[text()[contains(., 'follower')]]/span

Or this one:

//span[contains(following-sibling::text(), 'follower')]
qwermike
  • 1,446
  • 2
  • 12
  • 24