How to get Row Count in a table using selenium webdriver

Script to count no. of rows in a table using Selenium Webdriver
package selenium_examples;

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Example {
 public static void main(String[] args)
     {

  WebDriver driver = new FirefoxDriver();
 
  driver.get("http://www.w3schools.com/html/html_tables.asp");
 
  WebElement table_element = driver.findElement(By.xpath("//html//body/table"));
       Listtr_collection=table_element.findElements(By.xpath("//html/body/div[3]/div[1]/div/div[2]/table[1]/tbody/tr"));
     System.out.println("NUMBER OF ROWS IN TABLE = "+tr_collection.size());
 
 
  }
 
}

Output:- NUMBER OF ROWS IN TABLE = 5

 

No comments:

Related Posts Plugin for WordPress, Blogger...