简体   繁体   中英

How do I differentiate between buttons?

I don't know anything about writing code but I'm trying to write a script to automatically block people on Instagram but I'm having trouble because the report button and block buttons have the same name.

<button class="aOOlW -Cab_ " tabindex="0">Report User</button>

<button class="aOOlW -Cab_ " tabindex="0">Block this user</button>

If I use "aOOlW -Cab_" then it just clicks the report button over and over again and if I use the whole class then it doesn't click on anything.

Any help is appreciated

You can search for the correct button by checking for the text of each button with something like this:

var btns = document.getElementsByClassName("aOOlW");
for (var i = 0; i < btns.length; i++) {
  if (btns[i].innerHTML == "Block this user") {
    btns[i].click();
  }
}

This is assuming the buttons aren't a part of your own code. If they are a part of your own code, you can just add id tags to them like this:

<button class="aOOlW -Cab_   " id="report" tabindex="0">Report User</button>
<button class="aOOlW -Cab_   " id="block"  tabindex="0">Block this user</button>

And get the correct button with:

document.getElementById("block");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM