I am using selenium to test my webapp with chromedriver however selenium doesn’t seem able to find the element which I want.
The html I am querying is:
<table>
<thead><thead>
<tbody>
<tr>
<td></td>
<td>
<span class="class1">
<span>Test text</span>
</span>
<ul>
<li class="class2"><a href="#">Edit</a></li>
<li class="class2"><a href="#">Remove</a></li>
</ul>
</td>
</tr>
</tbody>
</table>
I am trying to select the web element:
<a href="#">Edit</a>
I have tried the following using CSS selectors:
table > tbody > tr:first-child > td:nth-child(2) > ul > li:first-child > a
and the same sort of query using XPath:
//table/tbody/tr/td/following-sibling::td[1]/ul/li/a
When I debug this and use a quickwatch to dynamically modify the query both queries work up until I try and select the ul; for example:
table > tbody > tr:first-child > td:nth-child(2)
AND
//table/tbody/tr/td/following-sibling::td[1]
Both correctly select the contents of the correct td containing the ul. When I try to make either of them get the ul, each of the selections becomes null.
So I have two problems, why am I not able to select the ul element using either CSS selectors or XPath and is there another technique I can use to select the first tag in the list with text “Edit”.
Cheers
Not really sure why your selector would break after you add
ul, but try this CSS selector as an alternative:Or this equivalent XPath expression: