How To Get Table Rows in Selenium??

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

Below is an example of a table.

Name Salary
Animesh 5000
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"))
How To Get Table Rows in Selenium?? How To Get Table Rows in Selenium?? Reviewed by Animesh Chatterjee on June 16, 2015 Rating: 5

No comments:

Powered by Blogger.