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
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"));
List
System.out.println("NUMBER OF ROWS IN TABLE = "+tr_collection.size());
}
}
Output:- NUMBER OF ROWS IN TABLE = 5
No comments:
Post a Comment