I have this button And i want you to help me to click it with javascript code. Here is the class of the button.
Before click
<a class="UFILikeLink" href="#" role="button" aria-label="Like this" aria-live="polite" data-ft="{"tn":">"}" data-reactid=".19l">
<i class="UFILikeLinkIcon img sp_nbjSKc2Bl8j sx_49c162" data-reactid=".19l.0"></i>
<span data-reactid=".19l.1">Like</span></a>
After click
<a class="UFILikeLink UFILinkBright" href="#" role="button" aria-label="Unlike this" aria-live="polite" data-ft="{"tn":">"}" data-reactid=".19l">
<i class="UFILikeLinkIcon img sp_nbjSKc2Bl8j sx_df3f80" data-reactid=".19l.0">
</i><span data-reactid=".19l.1">Like</span></a>
And here is the javascript code that im trying to make it work but i get error
var el = document.getElementsByClassName('UFILikeLink');
for (var i=0; i<el.length; i++) {
var ele = el[i];
if (ele.parentNode.className.indexOf('Unlike this') == -1) {
ele.click();
}
}
But when i try the code again it is pushing the already pushed buttons. Can you help me find the correct "if statement" so the code to see if any button is pushed, not to push it again?
Thanks for your time.
aria-labelele.parentNode.getAttribute("aria-label").indexOf("Unlike this") == -1