Get all data from tables

This is a simple solution to get all of the data from a table as web element. Later on, when you get the web element you can manipulate it as much as you want, select, compare, assert.

public List extractTableElementsToList(ETable tbl){
    System.out.println("Entering extract all elements from the table via helper.");
    List allTable = null;
    allTable = tbl.findElements(By.tagName("tr"));
    return allTable;
}

This will return the list with all visible table elements.

If you have a case that your table expands and reveals more content after you click on previous elements, you can always get the list of table child elements by using a simple script:

public List extractTableChildElementsToList(ETable tbl){
    System.out.println("Entering extract all elements from the table.");
    List allTable = null;
    allTable = tbl.findElements(By.tagName("td"));
    return allTable;
}

It’s essentially the same but uses TD instead of tr which indicates a child in a table, so this collects all of the visible table child elements and adds it to the list.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s