1

I have a table which is dynamic (so i can't use strict locator or paths)

<tbody>
<tr class="odd" role="row">
<td>Company</td>
<td class="sorting_1">
<td>22222@222222</td>
<td>0</td>
<td>0</td>
<td>
<td>12/28/2016 04:13:10</td>
<td class=" checkbox-cell width-to-content">
<div class="checkbox">
<label>
<input class="mass-action" name="mass-action" value="" type="checkbox"/>
<span class="checkbox-material">
<span class="check"/>
</span>
</label>
</div>
</td>
</tr>
<tr class="even" role="row">
<tr class="odd" role="row">
<tr class="even" role="row">
</tbody>

I tried to solve it in two steps, like this:

WebElement row = tableBody.findElement(
By.xpath("//*[contains(text(),'222222@222222')]/parent::tr"));
WebElement targetEl = row.findElement(By.className("check"));

But this solution is terrible and totally ineffective. Can anyone suggest some ideas how to make it more effectively?

Thank you!

3

Assuming that you want to select the span element with the class check.
You need to search for the tr that contains your text and continue from there.

//tr[.//td[contains(text(),'@')]]//span[@class='check']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.