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

225
Visualizações
How to set delay in random function?

I write a short code for browser automation testing on my website, browse random part of the website and just basic navigation, i want a small delay between the navigation. But setTimeout(); aint gonna cut it because when browse(); it skipped all setTimeout(); in sequence and i cant get it to work.

function findError() {
  if (window.find('Error')) {
    window.location.reload();
  }
}
function browse(url) {
  window.location.assign(url);
}
function click (x,y) {
  document.elementFromPoint(x,y).click();
}
var funcs = [
  func1,
  func2
]
function execute() {
  var i = Math.floor(Math.random() * funcs.length)
  funcs.splice(i-1, 1)[0]()
}
for ( var i = 0; i < 30; i++ ) {
  function func1() {
    browse('https://google.com')
    setTimeout(function() {findError();}, 10000);
    setTimeout(function() {click(420,540);}, 20000);
  }
  function func2() {
    browse('https://netflix.com');
    setTimeout(function() {findError();}, 10000);
    setTimeout(function() {click(1210,310);}, 20000);
  }
  setTimeout(function() {execute();}, 40000);
}

I have tried to use this delay but it only work on top of body modules, not in another function

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
await sleep (ms);

Do you have any idea ? Please help me

about 4 years ago · Juan Pablo Isaza
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