Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!