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

125
Vistas
Click buttons in an website with javascript based on the their class and their child

How can I press all the buttons in a page given the html code below?

I want to get the button name, and if the child value matches favorite_border to automatically press the button.

<button type="button" class="UnstyledButtonreact__UnstyledButton-sc-ty1bh0-0 btgkrL"><i size="20" aria-label="Favorite" value="favorite_border" class="Iconreact__Icon-sc-1gugx8q-0 FavoriteIconreact__StyledIcon-sc-289aae-0 irmnIh fNbWaJ material-icons">favorite</i></button>

So far I've came up with the follwoing javascript code but the problem is that for other buttons are getting pressed too breaking the flow and redirecting me to a separate page.


var buttons = document.getElementsByClassName('UnstyledButtonreact__UnstyledButton-sc-ty1bh0-0 btgkrL');

 for(var i = 0; i < buttons.length; i++)  
     buttons[i].click();
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

After a few more searches I figured the answer myself. The final code is:

var buttons = document.getElementsByClassName('UnstyledButtonreact__UnstyledButton-sc-ty1bh0-0 btgkrL');


for(var i = 0; i < buttons.length; i++)
    var btn = buttons[i];
    var child = btn.firstChild;
    if (child.innerHTML == "favorite_border") {
        buttons[i].click();
}

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