John Smith
John Smith

Reputation: 75

Clicking a dynamic button with Playwright: How to identify by class name

enter image description here

How can I use Playwright to click on the button in the image, identified by its class name? It's important to note that the button's name changes daily, starting with 'Collect 10 Candies' and incrementing by *2 each day, before resetting every week.

Upvotes: 0

Views: 4746

Answers (2)

John Smith
John Smith

Reputation: 75

This is the solution that worked for me:

page.query_selector("button[data-action='click->points#claimCandy'][data-target='points.button']").click()

Upvotes: 0

AutomationAndy
AutomationAndy

Reputation: 982

Your locator for that class can be this:

.collect-candy-button

so:

page.locator(`.collect-candy-button`).click()

Upvotes: 2

Related Questions