'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();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
