Reputation: 41
I want to click AutoTestSKU of the table below. How do I do it using selenium Java?
<tr class="poslist-item" onclick="callManage(this, 'a[id$=linkManageProduct]')">
<tr class="poslist-item" onclick="callManage(this, 'a[id$=linkManageProduct]')">
<tr class="poslist-item" onclick="callManage(this, 'a[id$=linkManageProduct]')">
<td>
<input id="listProductform:productItemRepeat:2:checkbox" class="toggle-checkbox" type="checkbox" onclick="event.stopPropagation();" value="true" name="listProductform:productItemRepeat:2:checkbox">
</td>
<td> Cash Withdraw </td>
<td>AutoTestSKU</td>
<td>AutoProductName</td>
<td> 1 </td>
<td> 999 </td>
<td> 0 </td>
<td> 0 </td>
<td>
<td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row-fluid row-break">
Upvotes: 3
Views: 128
Reputation: 16201
I will go with xpath
text based search. I also found element load issue is very common with webtables
so make sure to use explicit
wait as needed. See this for implementation.
//td[.='AutoTestSKU']
.
gives you the ability to directly point to the parent in html
hierarchy
If the text contains any whitespace it will not work. In that case you can use xpath contains()
function.
//td[contains(text(),'AutoTestSKU')]
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//td[contains(text(),'AutoTestSKU')]")));
myDynamicElement.click();
Upvotes: 2