Vkontakte is my group and I am writing a script for inviting some of its participants to meetings (list of names, or ID)

How to find the desired item by the contents of the href = tag and click the button located in the parent div?

<div class="friends_user_row clear_fix" id="random"> <div class="friends_photo_wrap" onmouseover="uiPhotoZoom.over(this, random)"> <a class="friends_photo _online" href="/id123456"><img class="friends_photo_img" alt="иван иванов" src="https://pp.me/123.jpg"></a> </div> <div class="friends_controls"> <button class="flat_button button_small button_wide" onclick="return Friends.inviteToGroup(this, random, random, 0, 'random')">Выслать приглашение</button> </div> </div> 

  • Click on the button should be automatic, through the script ?? - L. Vadim
  • click through the script - Dinuma88

1 answer 1

 var res = document.getElementsByTagName("a"); for(i=0; i < res.length; i++) { if(res[i].href == "http://localhost/id123456"); { let bt = res[i].parentNode.parentNode.querySelector('.flat_button'); Friends.inviteToGroup(bt, random, random, 0, 'random') } }