The below code is working fine with the added delay of 75secs but that delay is not static, it changes according to the size of the file so I want to remove that delay and substitute that with a better solution. After clicking on "Save & Continue" button, the page fetches data for 2-4 mins and then it clicks on the "Let's start" button.
I tried delay function and it's working fine with it but since fetching the data is not static, I want a better solution.
//function to add delays
const delay = (time) => new Promise((resolve) => setTimeout(resolve, time));
//another save and continue click
const saveContBtn2 = await page.waitForSelector(
'::-p-xpath(//button[text()="Save & Continue"])'
);
await saveContBtn2.click();
//let's start click
await delay(75000);
const letsStart = await page.waitForSelector(
'::-p-xpath(//button[text()="Let\'s start"])'
);
await letsStart.click();
waitForResponse
,waitForFunction
orwaitForSelector
? If the Let's Start button appears only after the response arrives, then you can just remove the delay and increase the timeout on thewaitForSelector
to 5 minutes. But answering this requires seeing the actual page, or a reproduction of it. See minimal reproducible example