Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

87
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda