'TimeoutError: Timeout exceeded while waiting for event after click on button in autotest

Registration on the site consists of three stages. The first step is to provide a name, email address. When you submit the form of the first step, you are redirected to the second step (confirmation by email). The URL changes in the browser, and confirmation email sends to the mail. For implement the autotest, we decided that we would always register the same email address. For confirmation in the request for this email you will receive a confirmation link. Sample code below.

await page.click(btnSignUp)
const [response] = await Promise.all([
   page.waitForResponse((response) =>response.url()===apiURL+'/register'), 
   {timeout: 30 * 1000}
])
const responseData = await response.json()

After clicking on the "Register" button, I see the following page (confirm email), but I cannot get a response to the request. I see the response in the terminal when performing an autotest. But I got the error "TimeoutError: Timeout exceeded while waiting for event" What is the problem, help me figure it out, please.



Solution 1:[1]

I am attaching code snippet. You can use that and modify according to your scenario. It helps in dealing with timeout error related issues.

const puppeteer = require("puppeteer");
const { scrollPageToBottom } = require('puppeteer-autoscroll-down')

async function scrape () {

const browser = await puppeteer.launch({headless: false});
const page =  await browser.newPage();

await page.goto("https://twitter.com/elonmusk", {waitUntil: "networkidle2"});

let isLoadingAvailable = true // Your condition-to-stop

while (isLoadingAvailable) {
    try{
        await scrollPageToBottom(page, { size: 250 , delay: 500})
        await page.waitForResponse(
        response => response.url() === 'https://twitter.com/elonmusk' && response.status() === 200
        )

    } catch (ex) {
        continue;
        
    }
    isLoadingAvailable = false // Update your condition-to-stop value
}

console.log("Loading done")
await browser.close();
};
scrape();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Furqan Ali