How To Get Table Rows in Selenium??


Share and Enjoy !

This is a very important implementation for selenium to find rows of a given table.

Below is an example of a table.

Ads code goes here
Rohan 7000

Now if we want to get rows of the table,we need to perform the following steps:

  1. First go Inspect element or firebug to determine the table name or id.[we can get the table by tag name also]
2.Now the corresponding code goes like
int count = 0;
List rows = driver.findElements(By.xpath("//table//tr"));
for(WebElement row: rows){
System.out.println("The number of rows that are visible is: "+ count);

instead xpath we can also find it by id or name like—

WebElement table=driver.findElement("Employee"));
if name is there
WebElement table=driver.findElement("name of the table"));
List rows=table.findElement(By.tagName("tr"))

Share and Enjoy !

READ  How To Sync Applications With Selenium Execution

Leave a Comment

Your email address will not be published. Required fields are marked *