You can only use getElementById
in the page context. Use page.evaluate
, eg:
const html = await page.evaluate(() => {
return document.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) => {
return document.getElementById("g-recaptcha-response").value = arg;
}, '123');
That'll set the value of the textarea to 123
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…