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

139
Visualizações
How to execute a series of dispatchevents in javascript and wait after each one is completed

I'm writing a chrome extension where I need to simulate user clicks on a webpage before pasting information into fields. The page has a listbox with onchange javascript (not mine) attached to it. Depending on the selection of the listbox the page shows different kind of information. So basically I want to execute a series of dispatchEvents.

The issue I have is that I need to wait until the onchange javascript on the listbox is done with it's thing before moving on to the next dispatchEvent in order to refer to new elements created by the onchange javascript. How do I do that?

If I just do one call like this:

elmt = document.getElementById('freightServiceSelect');
elmt.selectedIndex = 24;
elmt.dispatchEvent(new Event("change"));

it works fine. But if I then add the next call immediately after, like this:

elmt = document.getElementsByName("freightServiceAddon")[0];
elmt.checked = true;
elmt.dispatchEvent(new Event("click"));

it gets executed immediately and the element "freightServiceAddon" is at that point undefined.

about 4 years ago · Santiago Trujillo
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