Search code examples
web-scrapingplaywrightplaywright-python

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.


Solution

  • This is the solution that worked for me:

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