本文介绍了puppeteer:等待元素可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我是否可以告诉木偶操作员等到显示的元素。
I would like to know if I can tell puppeteer to wait until an element in displayed.
const inputValidate = await page.$('input[value=validate]');
await inputValidate.click()
//I want to do something like that
waitElemenentVisble('.btnNext ')
const btnNext = await page.$('.btnNext');
await btnNext.click();
我有什么方法可以做到这一点吗?
Is there any way I can accomplish this?
推荐答案
我认为您可以为此目的使用 page.waitForSelector(selector [,options])
函数。
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();
});
这篇关于puppeteer:等待元素可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!