Wait for text to appear when using Puppeteer

elena picture elena · Oct 19, 2017 · Viewed 14.7k times · Source

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});

Answer

nilobarp picture nilobarp · Oct 19, 2017

You can use waitForFunction. See https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagewaitforfunctionpagefunction-options-args

Including @elena's solution for completeness of the answer:

await page.waitForFunction('document.querySelector(".count").inner‌​Text.length == 7');