πŸš€ Selenium Automation Practice – Fetching Table Data Without Headers

in Olio di Balena β€’ yesterday

Hi Everyone,

I just Nowpracticed one of the most commonly asked Selenium interview questions:

πŸ‘‰ β€œHow do you fetch all row data from a web table, excluding the header details?”

I implemented this using Java + Selenium WebDriver + TestNG in Eclipse IDE, and executed the script with Microsoft Edge browser.

πŸ“ Step 1 – Script Preparation

Prepared a Selenium automation script in Java.

Used TestNG framework for execution and validation.

Goal: Fetch all table row data (only values, without headers).

πŸ“Œ Code Snippet:

**import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.testng.annotations.Test;

public class TableDataHandle {

@Test
public static void tableDataFetching() {

    // Set system property for Edge browser
    System.setProperty("webdriver.edge.driver",
            "D:\\Eclipse-workspace\\SeleniumInterviewPractices\\Drivers\\msedgedriver.exe");

    // Launch Edge browser
    WebDriver driver = new EdgeDriver();

    // Maximize window
    driver.manage().window().maximize();

    // Navigate to target webpage
    driver.get("https://www.w3schools.com/html/html_tables.asp");

    // Locate all rows (excluding header)
    List<WebElement> rowData = driver.findElements(By.xpath("//table[@id='customers']/tbody/tr"));

    // Iterate over rows and fetch all columns
    for (WebElement row : rowData) {
        List<WebElement> cols = row.findElements(By.tagName("td"));

        for (WebElement col : cols) {
            System.out.print(col.getText() + "  ");
        }
        System.out.println();
    }

    // Close browser
    driver.quit();
}

}**

🌐 Step 2 – Browser Launch (Edge)

Script executed successfully with EdgeDriver.

*Microsoft Edge browser" launched and navigated to the target web page containing the table.

πŸ“Έ Screenshot – Edge Browser Launch

πŸ“‹ Step 3 – Console Output

All table data (only values, excluding headers) was printed successfully in the console.

Verified results matched expected values.

πŸ“Έ Console Output Screenshot

βœ… Step 4 – Validation with TestNG

Added TestNG assertions to validate successful table data fetch.

Validation Passed – Test case executed correctly.

πŸ“Έ TestNG Execution Summary Screenshot

🎯 Final Result

βœ” Script executed successfully in Eclipse IDE.
βœ” Edge browser launched and navigated correctly.
βœ” Table data fetched and printed (headers excluded).
βœ” TestNG test case passed.
βœ” Captured screenshots for Edge browser, console output, and execution summary.

"πŸ’‘ Learning Outcome*

This practice helped me:

Understand table handling with Selenium.

Improve my TestNG validation and reporting.

Successfully run automation using Microsoft Edge browser.

Thanks for reading!