Selenium + Python · Lesson 26 of 43

0/43 done

Module 26: Web Tables

26. Dynamic Data Tables & Pagination Automation

16 minlesson

Your task

Implement count_table_rows(driver, table_xpath):

  1. Locate rows via By.XPATH f"{table_xpath}//tbody/tr".
  2. Return len(rows).

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

Parsing Web Tables in Python

python
rows = driver.find_elements(By.XPATH, "//table[@id='orders']//tbody/tr")

for row in rows:
    cells = row.find_elements(By.TAG_NAME, "td")
    order_id = cells[0].text
    status = cells[1].text
    if status == "PENDING":
        row.find_element(By.XPATH, ".//button[text()='Approve']").click()
        break

Key Takeaways & Walkthrough Summary

Data tables display records such as invoices and orders. In this lesson, you will master row-by-row traversal, extracting cell text, and locating action buttons inside specific table rows using XPath axes in Python. Let's master web tables!

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

Common Doubts & Lesson Q&A

Why start child locators with './/' instead of '//'?

'.//' restricts search to children of that specific row. Leading '//' starts at the root of the document, always returning the very first match on the page.

Ready? Solve the task in the editor

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

Python
Skip