I am constructing an XPath which selects cells in a grid, indexed by column and row. I have two types of grids in the application. One is a regular grid and another has nested grids (inside of its 's).
I want a single XPath which works for both grids.
(Yellow cell coloring indicates XPath selection)
Regular Grid:
XPath:
//*[@id='regularGrid']//table/tbody/tr[1]/td[1]
HTML:
<div id="regularGrid">
<table>
<tbody>
<tr role="row">
<td>Things</td>
<td>Things</td>
</tr>
<tr></tr>
</tbody>
</table>
</div>
Nested Grid (Incorrectly selecting the nested TDs):

XPath:
//*[@id='gridWithNestedGrid']//table/tbody/tr[1]/td[1]
HTML:
<div id="gridWithNestedGrid">
<div class="k-grid-content">
<table>
<tbody>
<tr class="k-master-row ng-scope" role="row">
<td>1390</td>
<td>1625</td>
<td>625</td>
</tr>
<tr class="k-detail-row ng-scope" role="row">
<td class="k-detail-cell">4167</td>
<td class="k-detail-cell">486</td>
<td class="k-detail-cell">6834</td>
</tr>
<tr></tr>
</tbody>
</table>
</div>
Problem: I need an XPath which works for both grids that doesn't select nested grids. The problem is that the nested grid div is nested inside of a div.
The following XPath works for the nested grid:
//*[@id='gridWithNestedGrid']/div/table/tbody/tr[1]/td[1]
But I need one that works for both.


Aucun commentaire:
Enregistrer un commentaire