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

Time:01-13

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.

CodePudding user response:

Your locator for that class can be this:

.collect-candy-button

so:

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

CodePudding user response:

This is the solution that worked for me:

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