In this session you will learn How to get a particular desired value from a web table and how to get maximum value in particular Column of a web table
*******************************************************************
You can get complete programs from below GitHub Repository
*******************************************************************
github.com/knowledgeshare-technologies/SeleniumBas…
*******************************************************************
You can see step by step selenium sessions from below playlist
*******************************************************************
• How to handle WebTables using Selenium Web...
***********************************************
For regular updates you can join this Group
***********************************************
www.facebook.com/groups/4754296501308288
****************************************************
Overview on Web Table
****************************************************
What is Web Table
Web Tables are Data Tables used to display Data in Tabular Format
Web Table data can be Static or Dynamic
What test we perform on this Web Tables
To Read Headers of the Table
To Count Number of Rows displays to compare with Database Count
Example : To Sum up any Column
Example : To find Top 5 Companies from a table based on turnover
How to Handle Web Table
Finding the table /table header/table row/table data using XPATH
Using List#WebElement# to store the values
Finally we iterate through the values using loops / Iterator to perform validations as per requirement
***************************************************************
Example program for Handling Web Table
( Get desired value and Get Maximum value from a column )
***************************************************************
package com.seleniumbasics;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class WebTable_Example_GetData
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", ".\\drivers\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("the-internet.herokuapp.com/tables");
/* Number of Rows */
List rows=driver.findElements(By.xpath("//*[@id=\"table1\"]/tbody/tr"));
int no_of_rows=rows.size();
System.out.println("Number of rows/records in a webtable : " + no_of_rows);
/* Getting 1st Row - 4th Column Value */
WebElement first_member_due =driver.findElement(By.xpath("//*[@id=\"table1\"]/tbody/tr[1]/td[4]"));
System.out.println("1st Row - 4th Column Value is : " + first_member_due.getText());
Float max_due=0.00f;
Float final_max_due=0.00f;
for(int i=1;iLTno_of_rows;i++)
{
String max_dollar= driver.findElement(By.xpath("//*[@id=\"table1\"]/tbody/tr[" + (i+1) + "]/td[4]")).getText();
//System.out.println(max_dollar);
max_dollar=max_dollar.replace("$","");
max_due=Float.parseFloat(max_dollar); /* Convert from String to Float */
if(max_dueGTfinal_max_due)
{
final_max_due=max_due;
}
}
System.out.println("Maximum Due from the Web Table is : " + final_max_due);
}
}
コメント