Time to use everything you learned. These exercises go from simple to real-world. Do not skip them. Reading about locators is not the same as writing them. The muscle memory comes from practice.
Exercise 1: Role-Based Locators
Navigate to the Banking Portal login page
Find the Username and Password fields using getByLabel
Find the Login button using getByRole
Find the "Forgot Password" link using getByRole('link')
Assert the page heading is visible using getByRole('heading')
Run the test in headed mode and watch it pass
Exercise 2: Text and Placeholder Locators
Navigate to the Shopping Portal
Find the search bar using getByPlaceholder
Search for a product by typing into the search bar
Find a product name on the page using getByText
Use getByText with regex to find price elements matching /\$\d+/
Assert the expected product is visible
Exercise 3: Filtering and Chaining
Navigate to a page with multiple similar cards or rows
Find all product cards using a CSS locator
Use .filter({ hasText: ... }) to narrow to a specific card
Chain getByRole('button') on the filtered card to click its button
Verify the action succeeded (cart updated, page navigated, etc.)
Log the total count of cards using .count()
Exercise 4: Table Interactions
Navigate to a page with a data table
Find a row by its content: getByRole('row').filter({ hasText: ... })
Read a cell value from that row
Click a button in that specific row
Verify the table has the expected number of rows using toHaveCount
Verify the header row text using toHaveText with an array
Exercise 5: Assertions Deep Dive
Write a test that checks at least 6 different assertions: toBeVisible, toHaveText, toHaveValue, toBeEnabled, toBeChecked, toHaveCount
Use .not modifier on at least 2 assertions
Use regex matching in at least 1 assertion
Add a custom timeout to 1 assertion using { timeout: 10000 }
Verify the page title and URL using toHaveTitle and toHaveURL
Exercise 6: Pick Locator Challenge
Open Codegen: npx playwright codegen https://www.testerrank.com/topics/forms
Use Pick Locator on 10 different elements
For each element, note what locator the tool suggests
Write a test using those 10 locators with appropriate assertions
Run the test and make sure all locators resolve correctly
If an exercise feels easy, add constraints: no CSS selectors allowed, only getByRole. Or find the same element using three different locator strategies and compare which is most readable and resilient.
Key Point: Do all six exercises. Each one targets a different locator skill. The gap between reading about locators and actually writing them is enormous. Close that gap now.
Key Point: Six exercises covering role-based locators, text locators, filtering, tables, assertions, and the Inspector. Practice is how you build locator instincts.