Sometimes we need to iterate through out table and do some operations with that.
Example :
Example :
- Verify for expected values in table
- Sort table columns in ascending & descending order and verify.
In above both the cases we need to get the table data to verify. Lets see how to get the data from table.
Steps
- get table instance
- using above table instance , get all table rows
- iterate each row and get all columns values.
Logic
@Test
public void testTable()
{
WebElement table = driver.findElement(By.id("tableId"));
//Get all rows (tr tags)
List<WebElement> rows = table.findElements(By.tagName("tr"));
//Print data from each row (Data from each td tag)
for (WebElement row : rows) {
List <WebElement> cols = row.findElements(By.tagName("td"));
for (WebElement col : cols) {
System.out.print(col.getText() + "\t");
}
System.out.println();
}
}
public void testTable()
{
WebElement table = driver.findElement(By.id("tableId"));
//Get all rows (tr tags)
List<WebElement>
//Print data from each row (Data from each td tag)
for (WebElement row : rows) {
List
System.out.print(col.getText() + "\t");
}
System.out.println();
}
}
Happy Coding :)
Regards,
SantoshSarma
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.