Reputation: 61
Is there a way to locate a particular table data cell element based in a condition from another cell in the same row by XPath? I was able to locate the conditional cell by Xpath (//td[@role="gridcell"]//span[@title="Professional"])[1]. However, I am not sure how do I locate the target cell in the same row based on the result of the condition. The goal is to locate&click the anchor element in the target table header by the condition of title=professional from the other cell in the same row.
<table>
...
<tbody>
<tr>..</tr>
<tr>..</tr>
...
<tr>
<td>..</td>
<th>
<span class="xxx">
<a class="yyy" title="my_title">..</a>
</span>
</th>
<td role="gridcell">
<span class="abc">
<span title="Professional">Professional</span>
</span>
</td>
<td>..</td>
</tr>
...
</tbody>
</table>
Upvotes: 0
Views: 756
Reputation: 29052
Assuming that you refer to the <a class="yyy" title="my_title">..</a>
element as anchor element, you can use this XPath-1.0 expression
//td[@role='gridcell' and span/span[@title='Professional']]/preceding-sibling::th[1]/span/a
Another valid XPath based on the <tr>
element would be
//tr[td[@role='gridcell' and span/span[@title='Professional']]]/th/span/a
Upvotes: 1