Search code examples
javascriptgoogle-chrome-devtoolsdevtools

Use Google Chrome DevTools to click on the "Follow" buttons on the page


enter image description here

My current script:

document.querySelectorAll('.components-button components-button-size-mini components-button-type-orange desktop components-button-inline').forEach(btn => btn.click());

I am not able to understand why it is not working, until last week everything was ok when I sent the script and hit enter the buttons were clicked, now this is not happening anymore.

What do I need to adjust to make it work?

Link to Site:
https://booyah.live/users/42973126/followers


Solution

  • When you want to target an element that contains all the classes you specified, you need to separate the class names with a dot. For example:

    <div class="my-class another-class" />
    
    document.querySelector('.my-class.another-class')
    

    What you have is some element with the class .components-button that contains another element with element name components-button-size-mini that contains another element with name components-button-type-orange and so on. Of course in this example I don't think you have an actual element with such names.

    So to fix your code, follow the pattern I presented above for the selector string:

    .some-class.another-class.yet-another-class
    

    The above will target elements with the three classes as specified: some-class, another-class, and yet-another-class