I wish to grab an HTML
table and extract the number of rows it has. I stumbled upon a solution linked here link. However, the proposed solution always returns row count of 1. I've alswo tried the IList<IWebElement>
approach to get the length, but the result is the same. My table structure is pretty straightforward. Table's HTML
is below.
How to get the total number of <tr>
's?
<table id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXMainTable" class="dxgvTable" cellspacing="0" cellpadding="0" onclick="ASPx.GTableClick('splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea', event);" ondblclick="ASPx.GVTableDblClick('splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea', event);" oncontextmenu="return ASPx.GVContextMenu('splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea',event);" style="width:100%;border-collapse:collapse;empty-cells:show;table-layout:fixed;overflow:hidden;text-overflow:ellipsis;">
<tbody>
<tr class="dxgvArm">
<td style="width:28px;"></td>
<td style="width:200px;"></td>
<td style="width:210px;"></td>
<td style="width:180px;"></td>
<td style="width:100px;"></td>
<td style="width:250px;"></td>
<td style="width:180px;"></td>
<td style="width:180px;"></td>
<td style="width:180px;"></td>
<td style="width:150px;"></td>
<td style="width:170px;"></td>
<td></td>
</tr>
<tr id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXDataRow0" class="dxgvDataRow" style="">
<td id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_tccell0_0" class="dxgv" align="center" style="vertical-align:Middle;">
<img src="/Client/images/7.jpg" alt="" width="14px" height="16px">
</td>
<td class="dx-nowrap dxgv">12/19/2018 12:05:24 PM</td>
<td class="dx-nowrap dxgv">Osa test</td>
<td class="dx-nowrap dxgv" align="right">28</td>
<td class="dx-nowrap dxgv">.txt</td>
<td class="dx-nowrap dxgv">Selenium test</td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv">Normalno</td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dxgvHEC"></td>
</tr>
<tr id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXDataRow1" class="dxgvDataRow" style="">
<td id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_tccell1_0" class="dxgv" align="center" style="vertical-align:Middle;">
<img src="/Client/images/9.jpg" alt="" width="14px" height="16px">
</td>
<td class="dx-nowrap dxgv">12/17/2018 1:55:45 PM</td>
<td class="dx-nowrap dxgv">Osa test</td>
<td class="dx-nowrap dxgv" align="right">22</td>
<td class="dx-nowrap dxgv">.txt</td>
<td class="dx-nowrap dxgv">d1</td>
<td class="dx-nowrap dxgv">petar </td>
<td class="dx-nowrap dxgv">Normalno</td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dxgvHEC"></td>
</tr>
<tr id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXDataRow2" class="dxgvDataRow" style="">
<td id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_tccell2_0" class="dxgv" align="center" style="vertical-align:Middle;">
<img src="/Client/images/7.jpg" alt="" width="14px" height="16px">
</td>
<td class="dx-nowrap dxgv">12/14/2018 1:08:38 PM</td>
<td class="dx-nowrap dxgv">Osa test</td>
<td class="dx-nowrap dxgv" align="right">16</td>
<td class="dx-nowrap dxgv">.txt</td>
<td class="dx-nowrap dxgv">asdf</td>
<td class="dx-nowrap dxgv">petar </td>
<td class="dx-nowrap dxgv">Normalno</td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dxgvHEC"></td>
</tr>
<tr id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXDataRow3" class="dxgvDataRow" style="">
<td id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_tccell3_0" class="dxgv" align="center" style="vertical-align:Middle;">
<img src="/Client/images/7.jpg" alt="" width="14px" height="16px">
</td>
<td class="dx-nowrap dxgv">12/14/2018 1:03:33 PM</td>
<td class="dx-nowrap dxgv">Osa test</td>
<td class="dx-nowrap dxgv" align="right">19</td>
<td class="dx-nowrap dxgv">.txt</td>
<td class="dx-nowrap dxgv">bnmbnm</td>
<td class="dx-nowrap dxgv">petar </td>
<td class="dx-nowrap dxgv">Normalno</td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dxgvHEC"></td>
</tr>
<tr id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXDataRow4" class="dxgvDataRow" style="">
<td id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_tccell4_0" class="dxgv" align="center" style="vertical-align:Middle;">
<img src="/Client/images/7.jpg" alt="" width="14px" height="16px">
</td>
<td class="dx-nowrap dxgv">12/14/2018 12:48:38 PM</td>
<td class="dx-nowrap dxgv">Osa test</td>
<td class="dx-nowrap dxgv" align="right">18</td>
<td class="dx-nowrap dxgv">.txt</td>
<td class="dx-nowrap dxgv">vcxv</td>
<td class="dx-nowrap dxgv">petar </td>
<td class="dx-nowrap dxgv">Normalno</td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dxgvHEC"></td>
</tr>
<tr id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXDataRow5" class="dxgvDataRow" style="">
<td id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_tccell5_0" class="dxgv" align="center" style="vertical-align:Middle;">
<img src="/Client/images/7.jpg" alt="" width="14px" height="16px">
</td>
<td class="dx-nowrap dxgv">12/14/2018 12:40:11 PM</td>
<td class="dx-nowrap dxgv">Osa test</td>
<td class="dx-nowrap dxgv" align="right">21</td>
<td class="dx-nowrap dxgv">.txt</td>
<td class="dx-nowrap dxgv">gfdg</td>
<td class="dx-nowrap dxgv">petar </td>
<td class="dx-nowrap dxgv">Normalno</td>
<td class="dx-nowrap dxgv">ealo</td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dxgvHEC"></td>
</tr>
<tr id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXDataRow6" class="dxgvDataRow" style="">
<td id="splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_tccell6_0" class="dxgv" align="center" style="vertical-align:Middle;">
<img src="/Client/images/1.jpg" alt="" width="14px" height="16px">
</td>
<td class="dx-nowrap dxgv">12/7/2018 3:10:17 PM</td>
<td class="dx-nowrap dxgv">Osa test</td>
<td class="dx-nowrap dxgv" align="right">15</td>
<td class="dx-nowrap dxgv">.txt</td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv">petar </td>
<td class="dx-nowrap dxgv">Normalno</td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dx-nowrap dxgv"> </td>
<td class="dxgvHEC"></td>
</tr>
</tbody>
This is what I have tried so far:
int rowCount = Driver
.chrome
.FindElements(
By.XPath("//[@id=\"splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXMainTable\"]"))
.Count();
var rowCount1 = Driver
.chrome
.FindElements
(By.XPath("//*[@id=\"splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXMainTable\"]/tbody"))
.Count();
IList <IWebElement> table = Driver
.chrome
.FindElements(
By.XPath("//*[@id=\"splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXMainTable\"]"));
int rowCount = Driver.chrome.FindElements(By.XPath("//*[@id=\"splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXMainTable\"]")).Count();
<br/>var rowCount1 = Driver.chrome.FindElements(By.XPath("//*[@id=\"splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXMainTable\"]/tbody")).Count();
<br/>IList <IWebElement> table = Driver.chrome.FindElements(By.XPath("//*[@id=\"splitter_callbackWorkAreaPanel_workAreaUC_gvAdminArea_DXMainTable\"]"));
xpath
is till table and there is only 1 table so count will be 1 only