rival-black
rival-black15mo ago

Puppeteer waitForResponse in a loop. Is it possible?

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();
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?
1 Reply
Alexey Udovydchenko
Probably click not doing anything - try to debug at localhost with headfull browser, see if new data actually loaded in browser on second click

Did you find this page helpful?