I am trying to avoid using element id to click on button so all I need is to scroll down then I click on the button but sometime the page has different hight and I want to avoid that as well ..
The correct hight is about 1200 Y down but as I said some of pages has different hight and 1200 y is not going to help to click the button,
Here is what I did:
window.scrollTo(0,1600);
do{
window.scrollBy(0, -700);
document.getElementsByClassName('button1')[5].click();
i=undefined
}while(i !=undefined);
But I don’t know if I can use nested loop to scroll to the bottom of the page then to go up let say 700 so I can click the button
Thank you.
2
Answers
Folks I've figured it out, all we need is to use "await" after scrolling down and before scrolling up:
You don’t really have to it with
scrollBy()
. Just pass the id of the target location inwindow.location.href
.make sure you add
scroll-behavior: smooth;
otherwise it just snap to the bottom.