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

202
Vistas
How to wait for button to be clickable

I have a small chrome extension as a beginner project and I have the following situation.

Lets pretend I have a website with a search button. When the button is pressed, two options can come up:

  1. there is a search result with a button called "buy"
  2. there is no search result and so is no button "buy"

This is the relevant part of code I have:

        mouseEventClick('#search'); // Search btn

        await sleep(250); // hard coded sleep timer

        // here I need a way to wait for the #buy button is clickable.


        try {
            mouseEventClick('#buy'); // click buy btn
            
        } catch {
            await sleep(750);
            mouseEventClick('#back'); // no result - go back to search mask
        }

I would instead of the await sleep(250) I would like to make it that way that the app is waiting until the button #buy is loaded in the DOM and clickable. Then it should go into the try code block.

But I do not want it to wait forever. I would like to let it wait max. 1 second and if the #buy btn is not showing up after that 1 second, it should still go to try.

So what I want to achieve is a flexible sleep timer between clicking #search and the search result that waits exaclty until the element can be clicked, but not longer than 1 second.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When you use await you need to make function async to constantly listening listen for events.

like mentioned in this tread

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