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
📌 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
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!