Selenium + Python · Lesson 26 of 43
Module 26: Web Tables
Your task
Implement count_table_rows(driver, table_xpath):
Write it in the editor, then press Check answer (Ctrl + Enter).
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()
breakData 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.
'.//' 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.
___