3

I'm 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?

Alex Kulinkovich
6272 gold badges8 silver badges18 bronze badges
asked Jun 3, 2015 at 17:59

1 Answer 1

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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.