How to count the number of rows in a table using Selenium Java

Tal Angel :

I have a table with X rows in an HTML web page. How do I count the number of rows using Selenium Java and CSS or XPath expressions?

Example of my table:

<tbody id="MyTableId">
<tr> First Data row</tr>
<tr> 2nd Data row</tr>
<tr> 3rd Data row<tr>
</tbody>
Dipak Bachhav :

Try below solution :

List<WebElement> rowCount = driver.findElements(By.xpath("//tbody[@id='MyTableId']/tbody/tr"));
System.out.println("Num rows: " + rowCount .size());

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=409551&siteId=1