Hello Friends,
In this article , i will describe how to get number of rows and column in html table :-
Name | Age | Gender | City |
---|---|---|---|
Chandan | 30 | Male | Delhi |
tina | 29 | Female | Alaska |
Martin | 31 | Male | Goa |
merry | 25 | Female | Indianapolis |
jim | 35 | Male | Austria |
Nisha | 28 | Female | Mumbai |
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 :- {
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);
}
}
Total rows are :7
Total columns are :4
Row Text is :Chandan
No comments:
Post a Comment