I’m working on a web scraping project using Puppeteer and encountering an unusual error. The script functions well until a certain point where I’m attempting to wait for an element to appear.
try {
await browser.goto(targetUrl)
let mainFrame = await browser.frames()[0];
// waiting for nested frame to load
await browser.waitFor("iframe")
let nestedFrame = mainFrame.childFrames()[0]
// waiting for content section to appear
await nestedFrame.waitFor("div[data-section=content]", {timeout: 60000})
// clicking the header to expand
let header = await nestedFrame.$("div[data-section=content] h2")
await header.click()
let buttons = await nestedFrame.$$("div[data-section=content] form span button")
for (let btn of buttons)
{
await btn.click()
console.log('button clicked');
await nestedFrame.waitFor("div.upload-container")
console.log('container found');
let fileInput = await nestedFrame.$("input[type=file]")
await fileInput.uploadFile(filePath)
console.log('file uploaded');
await nestedFrame.waitFor("div.upload-container", { hidden: true })
console.log('upload completed');
}
} catch (error) {
console.trace(error);
}
The script stops working immediately after logging ‘button clicked’, leading me to suspect the issue lies with nestedFrame.waitFor. The error message displayed is:
Trace: Error: Evaluation failed: TypeError: Promise.resolve is not a function
at pollMutation (<anonymous>:18:22)
at waitForPredicatePageFunction (<anonymous>:8:11)
at <anonymous>:70:3
at ExecutionContext.evaluateHandle
What might be causing this Promise.resolve error? I’m currently using the latest version of Puppeteer.