Reputation: 137
I have the following table:
<table>
<tbody>
<tr>
<td>
<a href="/ResetPassword/1/"></a>
</td>
<td>
User1
</td>
</tr>
<tr>
<td>
<a href="/ResetPassword/2/"></a>
</td>
<td>
User2
</td>
</tr>
</tbody>
</table>
I want to find the a
-tag of the tr, where the data User2
is in the same row. I know that I can find an a
-tag with partial link like findElement(By.partialLinkText("/ResetPassword/"));
(the number 2 can change, so I can´t use it as seperator). But I need to seperate it by User. Is there a solution like tr.td.text("User2") > findElement(By.partialLinkText("/ResetPassword/"));
?
Upvotes: 1
Views: 198
Reputation: 357
U can try something like this(not sure though)-
List<WebElement> list=table.findElements(By.tagName("tr"));
List<WebElement> tdvalues=null;
for(WebElement web:list){
tdvalues=web.findElements(By.tagName("td"));
if(tdvalues.contains("User2")){
System.out.println(tdvalues.get(0).getText());//0th position contains the link
}
tdvalues.clear();
}
Upvotes: 0
Reputation: 29
Hi I was wondering if you could use the .getValue()
statement with /@a
at the end of the xpath to locate the attribute "a".
Main thing to do is find a bulletproof xpath to locate the User2 row once you have done that finding the value of "a" should be easy enough.
I hope this helps
Upvotes: 0
Reputation: 4683
This XPath should do the trick for you. .//tr[td[normalize-space(text())='User2']]//a
Just keep changing "User2" part with the desired user value.
Upvotes: 1