本文介绍了等待使用Puppeteer时出现文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有与Selenium中类似的方式来等待文本出现在特定元素上.我已经尝试过类似的方法,但是似乎没有等待:
I wonder if there's a similar way as in Selenium to wait for text to appear for a particular element. I've tried something like this, but it doesn't seem to wait:
await page.waitForSelector('.count', {visible: true});
推荐答案
您可以使用waitForFunction
.参见 https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagewaitforfunctionpagefunction-options-args
包括@elena解决方案的完整性:
Including @elena's solution for completeness of the answer:
await page.waitForFunction('document.querySelector(".count").innerText.length == 7');
这篇关于等待使用Puppeteer时出现文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!