'JavaScript to click buttons automatically in a sequence in a different page

I am trying to auto click a button that redirects to a new URL, and from there click a button. Both buttons need to be clicked one after another; however, the latter executes as soon as the first starts executing. I need it to wait and then execute. Is this possible to achieve since both buttons are getting triggered from the different pages?

They are of both domains, I did use async and wait, but it still doesn't wait for the other link to load fully and then trigger the button. I want the first button to completely load the page and then trigger the next button.

basically, I am trying to follow users from another user's follower list. In the list, you have to visit first the follower's profile(first trigger) and then follow the use(second button). Is there a better approach to do this?

Code:

var draft = document.getElementsByClassName('follow__name');
        console.log(draft.length)
        console.log("draft = ", draft)
        draft[2].click(); //<-button number
        console.log(draft[2]) 
        document.getElementsByClassName('Button_label__3jCra')[5].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