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();
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();
}