0

I am trying to compute xpath of an element based on its text content. Is there a way?

so far I need to have the tag to compute the xpath

//a[contains(., 'text to be found')]

I need some xpath without the tag. something like the following.

//*[contains(., 'text to be found')]

This doesn't work

arun15thmay
  • 1,062
  • 1
  • 9
  • 19
  • It seems to be related to [this post](http://stackoverflow.com/questions/5074469/xpath-find-text-in-any-text-node). – Dougui Dec 27 '13 at 15:28
  • 1
    @Dougui That gets the text inside the node. I need to select the node. – arun15thmay Dec 27 '13 at 15:43
  • The second XPath, with `*`, should work. The OP might have something else going on. And I always use `text()` never `.`. – Phlip Dec 27 '13 at 15:43
  • @Phlip when I tried //*[contains(text(), 'text to be found')] it took infinitely long time to fetch the node. so settled for the format I have mentioned as the answer – arun15thmay Dec 27 '13 at 15:52

1 Answers1

0

I managed to get it work with

//*[. = 'text to be found']

@Dougui Thank you for the correct direction :)

arun15thmay
  • 1,062
  • 1
  • 9
  • 19