I’m new to both XPath and Selenium. I have a need to be able to click a link with Selenium based on whether or not a span is as a certain text. The example code is:
<div>
<span>Fri</span>
<ul>
<li>
<a href=#></a>
</li>
</ul>
</div>
<div>
<span>Sat</span>
<ul>
<li>
<a href=#></a>
</li>
</ul>
</div>
My XPath expression is //*[text()[contains(.,'Fri')]] which finds the correct span. Now I thought I could use //*[text()[contains(.,'Fri')]]../ul/li/a, but that doesn’t work.
How can I do it?
The Selenium IDE command will be:
From here:
Notice, that you may not write
[1]at the end of the XPath expression to select the first node from all occurrences as the Selenium IDE does it by default.As you use the IDE you can also use easier to read CSS selector:
As for your initial XPath expression, you missed one slash before
../: