up:如何等待元素可见? [英] puppeteer: how to wait until an element is visible?
本文介绍了up:如何等待元素可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以告诉puppeteer等到显示一个元素.
I would like to know if I can tell puppeteer to wait until an element is 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();
});
要检查可用选项,请参阅 github关联.
To check the options avaible, please see the github link.
这篇关于up:如何等待元素可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文