Selenium xpath selector based on the element text

What would a Selenium xpath selector be for the following HTML:

<ul>
   <li>First</li>
   <li>Second</li>
   <li>Third</li>
</ul>

I need to make Selenium IDE locate the second item on the list based on the element text. I thought //li='Second' would do the trick, but apparently it does not.


I think this is what you are looking for

ul/li[contains(text(), "Second")]

and better still

ul/li[text() = 'Second']

If you want to get by text

[.= 'Second']

or

[text() = 'Second']

By.xpath( "//li[contains(text(), 'Second')]" )