MainMenu

Home Core Java Overview Maven Tutorials

Tuesday, 29 January 2019

Get Number of rows and column in html table

How to get Number of rows & column in html table



Hello Friends,
In this article , i will describe how to get number of rows and column in html table :-

NameAgeGenderCity
Chandan30MaleDelhi
tina29FemaleAlaska
Martin31MaleGoa
merry25FemaleIndianapolis
jim35MaleAustria
Nisha28FemaleMumbai


Video


Here is the code to get the Number of rows and column from the table

public class Tablequiz
{
WebDriver driver;
@BeforeTest
public void g() throws InterruptedException, InvalidFormatException, IOException
{
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\ChromeDriver\\new\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
Thread.sleep(3000);
driver.navigate().to("http://www.way2testing.com/2019/01/get-number-of-rows-and-column-in-html.html");
}
@Test
public void h()
{
int rownum = driver.findElements(By.xpath("//*[@id='csc']/tbody/tr[*]")).size();
System.out.println("Total rows are :-" +rownum);
int columnnum = driver.findElements(By.xpath("//*[@id='csc']/tbody/tr[2]/td")).size();
System.out.println("Total columns are :-" +columnnum);
String rowtext = driver.findElement(By.xpath("//*[@id='csc']/tbody/tr[2]/td[1]")).getText();
System.out.println("Row Text is :" +rowtext);
}
}

OUTPUT :-
Total rows are :7
Total columns are :4
Row Text is :Chandan

No comments:

Post a Comment