16. User-Facing Locators & Resilient Query Strategies

Accessible Locators Hierarchy

1. page.get_by_role("button", name="Submit") 2. page.get_by_label("Email Address") 3. page.get_by_placeholder("Enter password") 4. page.get_by_text("Welcome back") 5. page.get_by_test_id("checkout-btn")
row = page.locator("tr").filter(has_text="ORD-9421")
row.get_by_role("button", name="Cancel").click()

Task

  • Implement get_button_by_name(page, btn_name):
  • 1. Return page.get_by_role("button", name=btn_name)
πŸ’‘Common doubts
Did you like the problem?
Lesson 16 of 37
Python
Loading code editor…
Next