Selenium + Java · Lesson 27 of 44

0/44 done

Module 27: Web Tables

27. Extracting & Interacting with Dynamic Data Grids

16 minlesson

Your task

Implement getRowCount:

  1. Accept WebDriver driver and By tableLocator.
  2. Find element, locate rows via By.xpath(".//tbody/tr"), and return rows.size().

Write it in the editor, then press Check answer (Ctrl + Enter).

Table Row & Column Traversal

java
List<WebElement> rows = driver.findElements(By.xpath("//table[@id='users']//tbody/tr"));

for (WebElement row : rows) {
    List<WebElement> cells = row.findElements(By.tagName("td"));
    String username = cells.get(0).getText();
    String role = cells.get(1).getText();
    if ("ADMIN".equals(role)) {
        cells.get(2).findElement(By.tagName("button")).click(); // Click Edit
        break;
    }
}

Key Takeaways & Walkthrough Summary

Web tables present tabular data such as orders and user accounts. In this lesson, you will master reading table headers, iterating rows, locating specific cells dynamically using XPath, and validating paginated data. Let's master web tables!

Part of the Selenium + Java course (Selenium with Java). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why use By.xpath(".//tbody/tr") with a leading dot?

The leading dot searches strictly relative to the table element. Without the dot, XPath searches from the root document.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Java
Skip