Reputation: 7154
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.
Upvotes: 26
Views: 80646
Reputation: 2443
You can use like this:
//li[. = "Second"]
OR
//li[contains(., "Second")]
Here, contains
mean that you can match the partial text, so below one is also correct:
//li[contains(., "Seco")]
Upvotes: 5
Reputation: 1423
If you want to get by text
[.= 'Second']
or
[text() = 'Second']
Upvotes: 7
Reputation: 8548
I think this is what you are looking for
ul/li[contains(text(), "Second")]
and better still
ul/li[text() = 'Second']
Upvotes: 46