How to get row count for a table

Best practices, code snippets for common functionality, examples, and guidelines.
qa-auto
Posts: 59
Joined: Mon Aug 05, 2019 10:46 pm

How to get row count for a table

Post by qa-auto » Tue Nov 05, 2019 10:41 pm

All,

There are so many posts on this issue. Even still, it took me awhile this afternoon to get the row count on my table. Sharing this forward in case it can be a quick solution for someone else.

Table structure
Annotation 2019-11-05 153024.jpg
Annotation 2019-11-05 153024.jpg (53.11 KiB) Viewed 512 times
Repository element RxPath
div/table[@id='ctl00_MainContent_CustSrch_gvCustomerList']/tbody

TableUserCodeCollection
[UserCodeMethod]
public static int TableRowCount(Adapter element)
{
TBodyTag tbody = new TBodyTag(element);
int rowCount = tbody.Children.Count;
Report.Info("User", "Table size: " + (rowCount - 1).ToString());
// header is first row so subtract 1
return (rowCount - 1);
}

The KEY thing is to add '/tbody' to your RxPath.

Hope this is helpful!
Lorinda