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

88
Visualizações
How to make JavaScript Snippets work after page reloads, in Chrome?

Environment: Chrome, a simple Web Portal

I'm trying to do a simple browser automation.

In a HTML table, 1. Clicks the first link, 2. Change the dropdown value and 3. click Submit.

The code after button click is not executed, as the page loads after the button click.

var tbl = document.getElementById("incident_table")
tbl.rows[2].cells[2].getElementsbyClassName("linked")[0].click()
// below code is not executing, as the above click loads the page
document.getElementById("incident.state").selectedIndex = 1
document.getElementById("sysverb_update").click()

I can able to run the last 2 lines of code separately in console, it works.

But when executing as a snippet it didnt

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

this post is very similar to your question: preventDefault() on an <a> tag

what you want to do is prevent the default action of the javascript click event.

What you may also do is:

tbl.rows[2].cells[2].getElementsbyClassName("linked")[0].addEventListener('click', ()=>{
    preventDefault();
    //write here what should happen instead
    });

What this will do is prevent the default action "reload site" from happening

Edit: What i mean in the comment is the following:

if(localStorage.getItem("firstPartComplete") === null){
   //do first part
   //set completion status in localStorage
   localStorage.setItem("firstPartComplete", true);
}else{
   // do second part
   localStorage.removeItem("firstPartComplete");
}
about 4 years ago · Juan Pablo Isaza Relatório
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