Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
Promise is not resolved when the condition it's true (?)

I'm not able to understand why the promise is not resolved when the condition it's true. In my case, I'm working with Puppeteer and I'm trying to do scroll down to charge more google reviews. I select all container childs and the total of reviews. It's the same number, but it seems like that condition it's not true. I understand nothing...

My code:

console.log('he entrado');

            await page.evaluate(() => new Promise((resolve) => {

                const scroller = document.querySelector('.review-dialog-list');
                const totalChilds = document.querySelectorAll('.gws-localreviews__general-reviews-block > *').length;
                const totalReviews = document.querySelector('.z5jxId').innerText.slice(0, -8);

                if(totalChilds != totalReviews){
                    var timer = setInterval(() => {
                        scroller.scrollBy(0, 400);
                    }, 100);
                }else{
                    clearInterval(timer);
                    resolve();
                }
            }));

            console.log('he salido');

I can see the console.log with the message 'He entrado' but it never show me 'He salido'. I don't have any problems with the scroller and I check the selectors in browser console and both have the same value.

If somebody can help me or explain to me why my code is failing I'd be thankful. Hope you can understand me and if not, let me know and I will append more details. Thanks a lot!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're retrieving the scroller, totalChilds, and totalReviews only when page.evaluate first runs. You should retrieve them every time you scroll instead.

await page.evaluate(() => new Promise((resolve) => {
    const scroller = document.querySelector('.review-dialog-list');
    const timer = setInterval(() => {
        const totalChilds = document.querySelectorAll('.gws-localreviews__general-reviews-block > *').length;
        const totalReviews = document.querySelector('.z5jxId').innerText.slice(0, -8);
        if (totalChilds === totalReviews) {
            clearInterval(timer);
            resolve();
        }
        scroller.scrollBy(0, 400);
    }, 100);
}));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda