Hey everyone, I’m working on a small project and I need some help. I’m trying to use Puppeteer to pick a specific shoe size on StockX. Right now I want to select size 11 but I’m running into issues.
The problem is that all the size buttons have the same class. I tried using the data-testid attribute but it’s not working. I’m pretty new to Puppeteer and Node.js so I’m a bit lost.
As someone who’s worked extensively with Puppeteer for e-commerce scraping, I can tell you that StockX can be tricky. Their site uses React, which means elements are often re-rendered dynamically. Here’s what’s worked for me:
This approach is more resilient to changes in class names or data attributes. Also, remember that some sizes might be out of stock, so add error handling for that scenario.
Lastly, StockX sometimes uses lazy loading, so you might need to scroll the page to trigger size option rendering. Hope this helps!
hey man, i’ve dealt with similar stuff before. stockx can be a pain. have you tried using page.evaluate()? it lets you run js directly in the page context. something like this might work:
I’ve encountered similar issues when working with Puppeteer on dynamic sites like StockX. One approach that’s worked for me is using a combination of waitForSelector and evaluate. Here’s a snippet that might help:
This waits for any size button to be visible, then uses evaluate to find and click the size 11 button based on its text content. It’s more robust against changes in data attributes. Remember to add error handling for cases where the size isn’t available.