1

Below is an example of the elements involved. I'm trying to write an XPATH that points to the list element that contains the string "This Is The Text You're Looking For" but

li//[contains(text(), 'This Is The Text You're Looking For')]

doesn't work. Neither does using the wildcard character '*' in place of 'li' in the XPATH.

<li class = "yadda yadda yadda" tabindex="-1" role="option" aria-selected="false" data-value="3">
    <svg xmlns="https://something" viewBox="a b c d" class="yadda yadda yadda" focusable="false" aria-hidden="true"</svg>
     "&nbsp;"
     "This Is The Text You're Looking For"
     <span class="yadda yadda yadda"></span>
</li>

Why isn't my XPATH working, and what do I need to do to point to the list element in my example by looking for that string?

Trevor
  • 160
  • 1
  • 12

1 Answers1

1

First, it seems you have namespace declarations somewhere in the document. You have have to either take them into account or use the element's local-name().

Also, take a look at the difference between . and text() in xpath.

Then try this and see if it works:

//*[local-name()="li"][contains(., "This Is The Text You're Looking For")]
Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45