Initially two json files arrive on the site - the rest arrive after clicking the ‘load more’ button. I'm trying to intercept all requests. The example shows how I am waiting for the button to appear and click it accordingly. But so far I'm capturing only two requests - although there should be three, because I've already pressed the button once.
How can I wait for the rest of the xhr to intercept after pressing the ‘load more’ button?
const grab = async(url) => {
const browser = await puppeteer.launch({ headless: false});
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on("request", async (request) => {
const current = await request.url();
if (current.includes('betty-variants')) {
console.log(request.url())
}
//This clicking not working here, the page does not see this selector
// await page.waitForSelector('.well-sm.well p.text-primary.pull-left span', { timeout: 5000})
// await page.click('.well-sm.well p.text-primary.pull-left span')
// Allow the request to be sent
await request.continue();
});
await page.goto(url, { waitUntil: 'networkidle2' });
await page.waitForSelector('.well-sm.well p.text-primary.pull-left span');
await page.click('.well-sm.well p.text-primary.pull-left span')
await browser.close();
};
I tried getting the data after clicking on the button, but I only get the standard two json responses from the site.