简体   繁体   中英

puppeteer page.evaluate page not defined

I want to type inside an input with puppeteer, but it returns me an error: page is not defined

async function login(){
    const browser = await puppeteer.launch({headless: false});
    const page = await browser.newPage();
    await page.goto(url, {waitUntil: "networkidle2"});
    await page.evaluate(async() =>{
        await page.type('#i0116','prova', {delay:200})
        document.getElementById('idSIButton9').click();
    })
}

I cant use 'document.getElementById('i0116').value = 'prova';'

You cannot use page or page.type inside page.evaluate.

So the correct way to do is this,

await page.type('#i0116','prova', {delay:200})
await page.evaluate(async() =>{
  document.getElementById('idSIButton9').click();
})

or using the native page.click api from puppeteer,

await page.type('#i0116','prova', {delay:200})
await page.click('#idSIButton9')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM