Tuesday, 13 March 2018

How To Handle Webtable By Using Selenium WebDriver

                                How to Handle WebTable By Using Selenium WebDriver
=====================================================================

Sample Site : http://www.testingmasters.com/hrm/
UserName   : user01
Password     : pass1234

Selenium WebDriver Code ::
====================

WebDriver driver =new FirefoxDriver();

// #launching HRM LoginPage
driver.get("http://www.testingmasters.com/hrm/");

// # Enter UserName
driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("User01");

// # Enter Password

driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("Pass1234");

// # Click on Login Button

driver.findElement(By.xpath(".//*[@id='btnLogin']")).click();

// # Select Leave Tab
driver.findElement(By.xpath(".//*[@id='menu_leave_viewLeaveModule']/b")).click();

// # Select My Leave Tab
driver.findElement(By.xpath(".//*[@id='menu_leave_viewMyLeaveList']")).click();

// Identifying  All Rows, All Columns Data And Size In My Leave table

List<WebElement> WebTable=driver.findElements(By.tagName("tr"));
int countofrows=WebTable.size();

System.out.println(" number of rows "+countofrows);

for(int i=0;i<=countofrows-1;i++)
{

System.out.println(" all rows data text "+WebTable.get(i).getText());


List<WebElement> allcolumns=driver.findElements(By.tagName("td"));
int countofcolumns=WebTable.size();
System.out.println(" all columns in webtable "+countofcolumns);

for(int j=0;j<=countofcolumns-1;j++)
{
System.out.println(" Text of columns "+WebTable.get(j).getText());


}

}