Selenium + Java · Lesson 27 of 44
Module 27: Web Tables
Your task
Implement getRowCount:
Write it in the editor, then press Check answer (Ctrl + Enter).
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;
}
}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.
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.
___