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

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

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 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!