Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.7K
Views
titiritero: espera N segundos antes de continuar con la siguiente línea

En titiritero me gustaría esperar un tiempo definido antes de pasar a la siguiente línea de código.

Intenté poner un setTimeout en una función de evaluación, pero parece que simplemente se ignora

 console.log('before waiting'); await page.evaluate(async() => { setTimeout(function(){ console.log('waiting'); }, 4000) }); console.log('after waiting');

Este código no espera y solo escribe antes de esperar y después de esperar

Sabes como hacer esto?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Puedes usar una pequeña función de promesa,

 function delay(time) { return new Promise(function(resolve) { setTimeout(resolve, time) }); }

Luego, llámalo cuando quieras un retraso.

 console.log('before waiting'); await delay(4000); console.log('after waiting');

Si debe usar titiritero, use la función incorporada waitForTimeout.

 await page.waitForTimeout(4000)

Si aún desea usar page.evaluate, resuélvalo después de 4 segundos. No estás resolviendo nada.

 await page.evaluate(async() => { await new Promise(function(resolve) { setTimeout(resolve, 1000) }); });

Pero supongo que simplemente puedes usar los dos primeros ejemplos.

over 4 years ago · Santiago Trujillo Report

0

he estado usando:

 await page.waitForTimeout(3000);

Donde 3000 es Milisegundos Y eso parece estar funcionando para mí.

over 4 years ago · Santiago Trujillo Report

0

Puede usar una de las siguientes opciones para esperar un segundo :

 await page.waitFor(1000); await frame.waitFor(1000); await new Promise(r => setTimeout(r, 1000));

Alternativamente, hay muchas funciones de Puppeteer que incluyen una opción de delay incorporada, que puede ser útil para esperar entre ciertos eventos:

 // Click Delay // Time to wait between mousedown and mouseup in milliseconds. Defaults to 0. await page.click('#example', {delay: 1000}); await frame.click('#example', {delay: 1000}); await elementHandle.click({delay: 1000}); await page.mouse.click(0, 0, {delay: 1000}); // Type Delay // Time to wait between key presses in milliseconds. Defaults to 0. await page.type('#example', 'Hello, world!', {delay: 1000}); await frame.type('#example', 'Hello, world!', {delay: 1000}); await elementHandle.type('Hello, world!', {delay: 1000}); await page.keyboard.type('Hello, world!', {delay: 1000}); // Press Delay // Time to wait between keydown and keyup in milliseconds. Defaults to 0. await elementHandle.press('Backspace', {delay: 1000}); await page.keyboard.press('Backspace', {delay: 1000});
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!