Puppeteer – Execution context was destroyed, most likely because of a navigation

I fixed that issue by using

await Promise.all([
      page.click('#submitButton'),
      page.waitForNavigation({ waitUntil: 'networkidle0' }),
]);
await page.goto('http:/www.example.com');
pageSource=await page.content();

step1_search_text="Enter your user ID in the format"

if (pageSource.indexOf(step1_search_text)==-1)
{
	console.log("["+ step1_search_text + "] is not found")
	return 0;
}
console.log("["+ step1_search_text + "] is  found")

await page.type('#userNameInput', 'username')
await page.type('#passwordInput', 'password)
await page.screenshot({path: '/puppeteer/step1.png'})
//The code below is the fix
await Promise.all([
      page.click('#submitButton'),
      page.waitForNavigation({ waitUntil: 'networkidle0' }),
]);

try {
	await page.screenshot({path: '/puppeteer/step2.png'})
	pageSource=await page.content();
	console.log(pageSource);
}
catch (e){
	
}

	

Leave a Reply

Your email address will not be published. Required fields are marked *