27. Extracting & Interacting with Dynamic Data Grids

Table Row & Column Traversal

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;
}
}

Task

  • Implement getRowCount:
  • 1. Accept WebDriver driver and By tableLocator.
  • 2. Find element, locate rows via By.xpath(".//tbody/tr"), and return rows.size().
πŸ’‘Common doubts
Did you like the problem?
Lesson 27 of 44
Java
Loading code editor…
Next