Playwright + Python · Lesson 16 of 37
Module 16: Locators
Your task
Implement get_button_by_name(page, btn_name):
Write it in the editor, then press Check answer (Ctrl + Enter).
page.get_by_role("button", name="Submit")page.get_by_label("Email Address")page.get_by_placeholder("Enter password")page.get_by_text("Welcome back")page.get_by_test_id("checkout-btn")row = page.locator("tr").filter(has_text="ORD-9421")
row.get_by_role("button", name="Cancel").click()Playwright locators represent a query that is evaluated right when an action occurs. In this lesson, you will master accessible user-facing locators like get_by_role, get_by_label, get_by_placeholder, and locator filtering. Let's master locators!
Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
If a locator resolves to more than one matching element, Playwright raises a strict mode violation error, highlighting UI ambiguities.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___