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

197
Views
no iterar hasta que se cumpla la condición

Mi mente está a punto de romperse tratando de resolver esto.

Estoy tratando de automatizar la adición de algunas máquinas a una lista desde la consola de Google Chrome, ya que el sitio web no es mío y no tengo acceso al código.

ingrese la descripción de la imagen aquí

Tengo una gran lista de máquinas que necesito agregar a la columna de la derecha, no puedo importarlas, por eso estoy tratando de automatizar el proceso.

Este es mi código:

 // input box var search = document.getElementById( "CustomControl_ml_ms_m_si_m_tic_pc_xAssignedResources_m_computerSelector_WrappedSelector_ml_ms_m_si_m_tic_pc_xAssignedResources_m_computerSelector_WrappedSelector_mainGrid_ctl00_SearchBox" ); // add to list btn const addToList = document.querySelector(".scbMiddleCell input:nth-child(2)"); // first item on the left column const primeraCelda = document.querySelector(".scgc"); // change the value of the input box search.value = "XXX-MXXXX"; // create a keyup event var ev = document.createEvent("Event"); ev.initEvent("keyup"); ev.which = ev.keyCode = 13; // run the event, this way the ajax function kicks in and i'm left with only one item in the left column search.dispatchEvent(ev); setTimeout(() => { // simulate the left item row selection primeraCelda.click(); }, 1000); setTimeout(() => { // click on the button to add the item to the right column addToList.click(); }, 1500);

Ahora, esto funciona solo cuando estoy usando un solo valor, si creo una matriz con valores y un bucle foreach, itera directamente a través de todos los elementos de la matriz y solo el último elemento se agrega a la columna derecha.

No puedo entender cómo NO iterar hasta que el elemento se agregue a la columna de la derecha.

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

0

Me tomó mucho buscar, pero finalmente pude encontrar una solución usando promesas, prometiendo setTimeout.

Encontré la solución en este hilo: promesa de JavaScript ES6 para bucle

 const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); for (let i = 0, p = Promise.resolve(); i < myArray.length; i++) { const element = myArray[i]; const celdaClick = () => primeraCelda.click(); const addtoListClick = () => addToList.click(); p = p .then(() => delay(1000, (search.value = element))) .then(() => delay(1000, search.dispatchEvent(ev))) .then(() => console.log(i)) .then(() => delay(1500, celdaClick())) .then(() => delay(1500, addtoListClick())); }
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!