-2

I am trying to count the total number of rows (excluding header) in my HTML table using Selenium Webdriver-Java.

Can someone please guide me in correct direction regarding the steps for the same?

Thanks in advance!

Ketan Deopujari
  • 113
  • 3
  • 3
  • 16

1 Answers1

6

If you could provide HTML around your table, we could provide more accurate selector in your case. Something like this should work. Hope you get the idea!

List<WebElement> rows = driver.findElements(By.cssSelector("table#dummyTable>tbody>tr"));
System.out.println("Total number of rows :"+ rows.size());

or using xpath

List<WebElement> rows = driver.findElements(By.xpath(".//table[@id='dummyTable']/tbody/tr"));
System.out.println("Total number of rows :"+ rows.size());
nilesh
  • 14,131
  • 7
  • 65
  • 79