Note that there are some explanatory texts on larger screens.

plurals
  1. POContinue the `while` loop when ExecuteScript(setInterval) is finished
    text
    copied!<p>I have a code that scrolls a growing page to the bottom (until it's not possible to scroll to the bottom).<br> When it's not possible, it scrolls to the top and the javascript code is finished.</p> <p>For example: imagine a timeline on facebook.<br> It's a growing page, so I can scroll it again and again until it's not possible to scroll (then I will be in: "BORN").</p> <p>So this is my code:</p> <pre><code>while (i &lt; elements.Count) { js.ExecuteScript("var timeId = setInterval( function() { if(window.scrollY&lt;(document.body.scrollHeight-window.screen.availHeight)) window.scrollTo(0,document.body.scrollHeight); else { clearInterval(timeId); window.scrollTo(0,0); } },5000);"); i++; } </code></pre> <p>I want to add 1 to <code>i</code> only when the <code>setInterval</code> is finished.</p> <p>I tried the next thing:</p> <pre><code>while (i &lt; elements.Count) { object a = js.ExecuteScript("setInterval( function() { if(window.scrollY&lt;(document.body.scrollHeight-window.screen.availHeight)) { window.scrollTo(0,document.body.scrollHeight); return '1'}; else { clearInterval(timeId); window.scrollTo(0,0); return '2'} },5000);"); while (a != '2') { // do nothing, this while will be ended when we arrived the bottom and // go back to the top } // all the page is loaded i++; </code></pre> <p>}</p> <p>but it doesn't work.. maybe there is a way to scroll to the bottom more and more and then to the top without using set interval? (but remember: it's a growing page that grows when you scroll it down and down.. </p> <p>How can I do it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload