Puppeteer Cannot Read Property Getelementbyid Of Undefined
I'm trying to pass a value to the browser created by the puppeteer, but this error appears: Cannot read property 'getElementById' of undefined async function start() { const
Solution 1:
You can only use getElementById
in the page context. Use page.evaluate
, eg:
const html = await page.evaluate(() => {
returndocument.getElementById("g-recaptcha-response").innerHTML;
});
console.log(html);
That'll take the the innerHTML
of that element, send it back to Puppeteer, and log it in Node.
If you want to pass something to the page, you'll have to pass it to page.evaluate
, eg
await page.evaluate((arg) => {
returndocument.getElementById("g-recaptcha-response").value = arg;
}, '123');
That'll set the value of the textarea to 123
.
Post a Comment for "Puppeteer Cannot Read Property Getelementbyid Of Undefined"