2

Hello I am currently trying to figure out how to get the count of how many rows are displaying in an HTML Grid on a page.

From researching several stack exchanges some people reference GetXPathCount but my compiler does not recognize this command nor can i find search results for a name space to make it work.

Preferably i would like to use something using By.Id or By.CssSelector. Could anyone assist me in a solution? Thank you.

2

The code that was entered by Brandon Garlock won't work for C# which you included in your tags, here is the C# version to help with the row count:

driver.FindElements(By.XPath("//table[@id='yourIDhere']//tr")).Count;

Also be aware that if you have a grid header row, you will want to filter that out so it doesn't throw off your count.

  • I was skeptical when i saw .size because its used to get height and width dimensions. Thanks will try this. – GuardTheGates Jun 3 '15 at 19:30
  • This does work and imo now that i have more experience is the best way to perform said task. – GuardTheGates Jan 9 '17 at 13:29
  • 1
    xpath is missing a closing ]: "//table[@id='yourIDhere']//tr" instead of "//table[@id='yourIDhere'//tr" – return Dec 20 '18 at 16:48
  • @07FwqiRQT you are quite right, that change is reflected – DEnumber50 Jan 21 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.