Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am trying to scrape the content of a particular Div tag from a gamming website. at first when you visit the site the div tag will have empty content with uncompleted class. example

<div class="ball ball-"><div>
then after every 45seconds the textContent and the class attribute will be dynamically added example

<div class="ball ball-red">45<div>
after every 45 seconds the textContent and the class attribute will change to another value.

At first it might look like this

<div class="ball ball-red">23<div>
after 45 seconds it will change maybe to something like this

<div class="ball ball-green">3<div>
after another 45 seconds it may look like this

<div class="ball ball-blue">33<div>
How can i make puppeteer to visit such page, wait for the class and the textcontent to be added to the div tag, and then grab whatever the class is also grab the textcontent & log it to console close puppetter and run it again.

I tried the below code and keep telling me selectElemClass is not defined or cannot read property length of undefined. please help.

you can inspect the result of the 6 ball on the page to see the behaviour am trying to explain. here is the website url Am just trying to get the class and text context of the firstball starting from the left. if i can succesfully get that to work, then i will repeat the same working process for the rest 5 balls.

What I have tried:

<pre>const puppeteer = require("puppeteer");

async function scrapeData(url){
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
const selectElemClass = await page.evaluate(() => {
    return document.querySelectorAll(".ball")[2].classList[1];
const hasClassArived = await page.waitForFunction(function(selectElemClass){
   return selectElemClass.length > 6;
hasClassArived ? console.log(selectElemClass) : console.log("failed");
Updated 23-Feb-23 21:14pm

1 solution

Hi bro, you can use: page.waitForSelector('selector', {visible:true})
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900