puppeteer: how to wait until an element is visible?

前端 未结 6 1703
粉色の甜心
粉色の甜心 2020-12-01 05:22

I would like to know if I can tell puppeteer to wait until an element is displayed.

const inputValidate = await page.$(         


        
6条回答
  •  隐瞒了意图╮
    2020-12-01 05:25

    I think you can use page.waitForSelector(selector[, options]) function for that purpose.

    const puppeteer = require('puppeteer');
    
    puppeteer.launch().then(async browser => {
      const page = await browser.newPage();
      page
        .waitForSelector('#myId')
        .then(() => console.log('got it'));
        browser.close();
    });
    

    To check the options avaible, please see the github link.

提交回复
热议问题