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

128
Views
Ejecutando un bucle retrasado de funciones en la consola de javascript

Espero que estés bien. Tengo algunos problemas para obtener un bucle retrasado en la consola de JavaScript. A modo de contexto, me encargaron crear una lista de correos electrónicos de nuestro CRM, pero la plataforma no permite exportar estos datos más allá de enumerarlos todos en una búsqueda.

Creé una matriz en blanco para enviar correos electrónicos, nos preocuparemos por obtener estos datos después:

 emailsList = [];

Así que necesito lo siguiente para cada fila de la tabla:

 function clickPopup() { //Click User Code to Trigger Ajax Popup document.querySelector("#tblReport > tbody > tr:nth-child(" + i + ") > td:nth-child(2) > a").click(); } function getEmailTextAndClose() { // Grab Dom Content in email variable var email = document.querySelector("#email_compose_link").innerText; // Push email to emailList array emailsList.push(email); parent.parent.$.fn.colorbox.close() }

todo esto funciona bien, pero donde estoy luchando es ponerlos en un bucle con un retraso, la ventana emergente necesita un segundo para extraer el contenido a través de ajax. Entonces, lo que he intentado:

 emailsList = []; function clickPopup() { //Click User Code to Trigger Ajax Popup document.querySelector("#tblReport > tbody > tr:nth-child(" + i + ") > td:nth-child(2) > a").click(); } function getEmailTextAndClose() { // Grab Dom Content in email variable var email = document.querySelector("#email_compose_link").innerText; // Push email to emailList array emailsList.push(email); parent.parent.$.fn.colorbox.close() } for(var i = 0; i < 100; i++) { setTimeout(function() { // after 1000ms, call the `setTimeout` callback // In the meantime, continue executing code below setTimeout(function() { getEmailTextAndClose() //runs second after 11000ms },1000) clickPopup() //runs first, after 10ms },10) }

Y:

 emailsList = []; function getEmailTextAndClose() { // Grab Dom Content in email variable var email = document.querySelector("#email_compose_link").innerText; // Push email to emailList array emailsList.push(email); parent.parent.$.fn.colorbox.close() } for(var i = 0; i < 100; i++) { clickPopup(i); } function clickPopup(i) { setTimeout(() => { document.querySelector("#tblReport > tbody > tr:nth-child(" + i + ") > td:nth-child(2) > a").click(); setTimeout(getEmailTextAndClose() 2000) }, 2000); getEmailTextAndClose(); }

Todas estas configuraciones no retrasan la segunda función o no incrementan las i en nuestro selector de consultas. ¿Estoy haciendo todo esto mal?

Muchas gracias.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intente usar una promesa con el código que activa la función ajax:

 function clickPopup() { return new Promise(function (resolve, reject) { //Click User Code to Trigger Ajax Popup document .querySelector( "#tblReport > tbody > tr:nth-child(" + i + ") > td:nth-child(2) > a" ) .click(); resolve(); }); } function getEmailTextAndClose() { // Grab Dom Content in email variable var email = document.querySelector("#email_compose_link").innerText; // Push email to emailList array emailsList.push(email); parent.parent.$.fn.colorbox.close(); } clickPopup().then(function () { getEmailTextAndClose(); });
about 4 years ago · Juan Pablo Isaza 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!