Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Get Data From Non-Table HTML Tag WebTable Using Selenium WebDriver

Posted on 02/08/2025 By admin

We have seen multiple posts on handling a web table in Selenium WebDriver. You can find them below:-

Storing Web Table Data Into List Of Map – Java

Storing Web Table Data Into A List Of Maps Using Java Stream APIs

Storing Web Table With Pagination Data Into List Of Map – Java

All above examples include a table created using table, thead, tbody, tr and td HTML tags. Many asked that in real-time we get non table tag web table also so provide an example of that as well.

Yeah, It’s true it is not mandatory to create a web table with table HTML tag only. It can be created using other tags as well. But the major part is that the handling mechanism is not different than the table tag. Just you need to play with locators.

I have taken a web table example developed using angular. I have performed below actions on this web table:-

  1. Get all headers and print.
  2. Get all rows excluding headers and print data of each column of a row with header name.
package WebTablesExamples; import java.time.Duration;
import java.util.ArrayList;
import java.util.LinkedHashMap;
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;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait; import io.github.bonigarcia.wdm.WebDriverManager; public class NonTableTrTdWebTable { public static void main(String[] args) { WebDriverManager.chromedriver().setup(); WebDriver driver = new ChromeDriver(); driver.get("http://demo.automationtesting.in/WebTable.html"); // Wait till web table is loaded WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.xpath("//div[contains(@class,'ui-grid-viewport')]//div[contains(@class,'grid-row')]"), 1)); // Let's get header first String headerLoc = "//div[contains(@class,'header-cell')]//span[contains(@id,'header-text')]"; List allHeadersEle = driver.findElements(By.xpath(headerLoc)); List allHeaderNames = new ArrayList(); for (WebElement header : allHeadersEle) { String headerName = header.getText(); allHeaderNames.add(headerName); } System.out.println("Headers are:-"); System.out.println(allHeaderNames); // Each row will be a key value pair. So we will use LinkedHashMap so that order // can be retained. // All map will be added to a list. List> allTableData = new ArrayList>(); // Get total rows count excluding headers String rowLoc = "//div[contains(@class,'ui-grid-viewport')]//div[contains(@class,'grid-row')]"; List allRowsEle = driver.findElements(By.xpath(rowLoc)); // Starting from 1 as xpath index starts from 1 for (int i = 1; i  allColumnsEle = driver.findElement(By.xpath(specificRowLoc)).findElements(By.xpath(".//div[contains(@class,'grid-cell-contents')]")); // Creating a map to store key-value pair data. It will be created for each iteration of row LinkedHashMap eachRowData = new LinkedHashMap(); // Iterating each cell for (int j = 0; j < allColumnsEle.size(); j++) { // Getting cell value String cellValue = allColumnsEle.get(j).getText(); // We will put in to map with header name and value with iteration // Get jth index value from allHeaderNames and jth cell value of row eachRowData.put(allHeaderNames.get(j), cellValue); } // After iterating row completely, add in to list. allTableData.add(eachRowData); } System.out.println("Table data are:-"); System.out.println("========================================="); for(LinkedHashMap data : allTableData) { for(String key : data.keySet()) { System.out.println(key + " : "+ data.get(key)); } System.out.println("========================================="); } driver.quit(); }
}
Headers are:-
[Email, First Name, Gender, Last Name, Phone, Action]
Table data are:-
=========================================
Email      : [email protected]
First Name      : Faculdade
Gender      : FeMale
Last Name      : Fadergs
Phone      : 1523611667
=========================================
Email      : [email protected]
First Name      : Faculdade
Gender      : FeMale
Last Name      : Fadergs
Phone      : 1523611867
=========================================
Email      : [email protected]
First Name      : Faculdade
Gender      : FeMale
Last Name      : Fadergs
Phone      : 9999968005
=========================================
Email      : [email protected]
First Name      : Faculdade
Gender      : FeMale
Last Name      : Fadergs
Phone      : 0007678678
=========================================
Email      : [email protected]
First Name      : Faculdade
Gender      : FeMale
Last Name      : Fadergs
Phone      : 0007678678
=========================================
Email      : [email protected]
First Name      : Faculdade
Gender      : FeMale
Last Name      : Fadergs
Phone      : 0007678678
=========================================
Email      : [email protected]
First Name      : Faculdade
Gender      : FeMale
Last Name      : Fadergs
Phone      : 0007678678
=========================================
Email      : [email protected]
First Name      : Faculdade
Gender      : FeMale
Last Name      : Fadergs
Phone      : 8523677452
=========================================
Email      : [email protected]
First Name      : Faculdade
Gender      : Male
Last Name      : Fadergs
Phone      : 8882300678
=========================================
Email      : [email protected]
First Name      : Faculdade
Gender      : FeMale
Last Name      : Fadergs
Phone      : 0007678678
=========================================

You can download/clone the above sample project from here.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: REST Assured Tutorial 26 – How To Use Java Object As Payload For API Request
Next Post: Interview Experience at CTS (Cognizant) Bangalore for Selenium Java Profile ( Sep – 2019)

Related Posts

Are Your Selenium Scripts Ready For Parallel Execution? Uncategorized
REST Assured Tutorial 21 – Get & Assert Response Time Of Request Uncategorized
Css – Make Selenium Easy Uncategorized
Java Programs 16: Java Program to Find Length of String Without Using Length Method Uncategorized
Interview Experience at Nous InfoSystem Bangalore for Automation Testing Profile Uncategorized
Hierarchy of Selenium Classes and Interfaces | Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark