Question

I am trying to identifying the table data for the below HTMLcode

<!-- You can use /goo.html to have your application be context sensitive -->
<!-- Add Any custom Tag Lib's required of your project down below -->
<div id="specialHandlingTableWrapper" style="height: 401px;">
<div id="specialHandlingTableHeader" style="width: 636px; position: relative; top: 0px; z-index: 10; vertical-align: top; height: 170px;">
<table id="specialHandlingSelectionTable" class="table table-striped table-hover table-striped data-table">
<thead>
<tbody>
<tr>
<td class="itemNameCell">SOD Catalog Test Code1 not inbound</td>
<td class="skuCell">SOD_CATALOG_SPECIAL_HANDLING</td>
<td/>
<td/>
<td/>
</tbody>
</table>
</div>

I need to get the 3rd column data and below is the xpath written for the same

@FindBy(xpath = "//table[@id='specialHandlingSelectionTable' and class='table table-striped table-hover table-striped data-table']/tr[1]/td[3]") 
public WebElement FirstHandlinginstr;

And the interesting part is that I am seeing 2 matching nodes even after defining the tr and td values.Please help me here!

Was it helpful?

Solution

Your XPath expression does not match the input, so I'm surprised you're getting a result anyway. From what you stated in the comments, in seems that for some reason it returns elements of both the table header and body elements (which it shouldn't query at all).

For getting the third table cell of the first row in (each) table body, use this query:

//table[@id='specialHandlingSelectionTable']/tbody/tr[1]/tr[3]

If there are multiple table body elements, and you only want to query the first row of all of them:

(//table[@id='specialHandlingSelectionTable']/tbody/tr)[1]/tr[3]

If you want to query the table headers instead, replace tbody by theader.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top