I am trying to find a better way to do this than using:
js.ExecuteScript(\"scroll(0, 1300)\");
I have a page where the data can change maki
I am going to take @ratsstack's answer little further and make it little easier for you to implement. I am not sure if there is a cleaner way to do this. But, at least something that should work. You can provide an estimated number of scroll you think is sufficient for the page to load fully. Notice you can provide more number than you think is correct. It does not really hurt or will not cause your script to fail.
public void ScrollPage(int counter)
{
const string script =
@"window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));";
int count = 0;
while (count != counter)
{
IJavaScriptExecutor js = _driver as IJavaScriptExecutor;
js.ExecuteScript(script);
Thread.Sleep(500);
count++;
}
}
Note: I am using Thread.Sleep()
to give the page sometime to finish loading. However, it is never recommanded to use hardcoded use. I am not sure about the technolgies you are using so really cannot provide any wait mechanism to wait for the page load. You can use something and replace the Thread.Sleep()
Implementation
ScrollPage(8);