Reputation: 96454
Given this HTML:
<tr class="even" id="district_22">
<td class="name">Virginia Beach City Public Schools</td>
<td class=""><a href="/admin/districts/22" class="member_link delete_link" data-confirm="Sure?" data-method="delete" rel="nofollow">Delete</a></td>
</tr>
<tr class="even" id="district_23">
<td class="name">Virginia City City Public Schools</td>
<td class=""><a href="/admin/districts/23" class="member_link delete_link" data-confirm="Sure?" data-method="delete" rel="nofollow">Delete</a></td>
</tr>
<tr class="even" id="district_24">
<td class="name">Virginia Town City Public Schools</td>
<td class=""><a href="/admin/districts/24" class="member_link delete_link" data-confirm="Sure?" data-method="delete" rel="nofollow">Delete</a></td>
</tr>
I am trying to use Selenium and xpath with it. I am having problems when trying to select the 'delete' link that belongs to 'Virginia Beach City Public Schools'. I am new to xpath.
I am trying:
xpath=(//td[text()='Beach')]/@class.contains('delete'))
but it is not finding the element.
Note: I cannot use the ID as these are repeated tests and the ID changes each time.
Upvotes: 2
Views: 237
Reputation: 7372
tr[@id="district_22"]//a[contains(@class,'delete_link')]
would be a lot better.
It's not good to look at the text. After all it may get localized and edited in other ways. ID's however are ment to be unchanging and not duplicated.
Upvotes: 1
Reputation: 39
I think you want to execute a automate scripts in loop, if this is the case then you can try the below code:
for(i=1,dist=22; i<-count; i++,dist++)
{
....
....
driver..findElement(By.xpath("//*[@id=District_"+dist+"]/..."))
}
Upvotes: -1
Reputation: 5678
Try this:
//td[contains(text(),'Beach')]/../td/a[contains(@class,'delete_link')]
Upvotes: 4