Apify and Crawlee Official Forum

Updated 4 months ago

Puppeteer waitForResponse in a loop. Is it possible?

Plain Text
        for (let i = 1; i <= 5; i++) {
            const [response] = await Promise.all([
                page.waitForResponse((res) => res.url() !== locationURL  && res.url().includes('/approved-used?')),
                page.click('.load-more button')
            ]);


            const d = await response.json();


Basically my code looks something like this. I click the load more button and want to grab ajax api call response data. It works only on the first try, then it just fails, due to waitForResponse never getting the response

Am I missing something?
A
1 comment
Probably click not doing anything - try to debug at localhost with headfull browser, see if new data actually loaded in browser on second click
Add a reply
Sign up and join the conversation on Discord