Reputation: 2478
I am trying select specific div located in <td></td>
tags mark based on text located in another <td></td>
tag. Probably html code will describe it easier:
<tr>
<td>
<div class="name">test1</div>
</td>
<td>
<div class="created">Tom</div>
</td>
<td>
<div class="custom">Disabled</div>
</td>
<td>
<div class="custom">Failed</div>
</td>
</tr>
<tr>
<td>
<div class="name">test2</div>
</td>
<td>
<div class="created">Tom</div>
</td>
<td>
<div class="custom">Disabled</div>
</td>
<td>
<div class="custom">Failed</div>
</td>
</tr>
<tr>
<td>
<div class="name">test3</div>
</td>
<td>
<div class="created">Kate</div>
</td>
<td>
<div class="custom">Disabled</div>
</td>
<td>
<div class="custom">Failed</div>
</td>
</tr>
So on this example what I would like to select by Xpath is the second row and div with Failed
text. But I can not use indexing because size and placement is not constant always and can change in time. So only unique field is div with class of name in my case test2
.
I was thinking of using maybe following-sibling
. Maybe something like this:
\\tr\div[@class='name' and text()='test1']
but what next? div
is not sibling but td
is.
Any ideas?
Upvotes: 0
Views: 1128
Reputation: 14145
If you are trying to get the status of the test based on Test Name then use the below xpath.
(//div[normalize-space(.)='test2' and @class='name']/ancestor::tr//div)[last()]
Upvotes: 1
Reputation: 2478
I was able to solve it by using:
//td/div[text()='test1']/ancestor::tr/td/div[@class='custom' and text()='Failed']
Upvotes: 1