Jump to content

Checking if Chrome reached bottom of a page - (Moved)

Recommended Posts



I have the following problem I need to write a script that opens different sites in the tabbar of Chrome, scrolls down each site and switches everytime,  it reached the bottom of a page. So far I managed it to open the sites and switch between them but my script right now is just depending on a specific time to switch which is unfortunate because the sites are not the same length So there is a difference in the waiting time between the sites while it still tries to scroll down. 

Because I'm new to autoit I don't know for sure if there is a function that could tell me if Chrome reached the bottom of a site like I found with getScrollPos in C++ .



Link to post
Share on other sites
  • Developers

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:


General development and scripting discussions.

Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

Link to post
Share on other sites

One way would be to use WebDriver and execute JavaScript to get the height of the document and compare it with the position of the scroll bar (or something similar) .

That seems to work quite well :

Local $JS_ScrollTop = Json_Decode(_WD_ExecuteScript($sSession, 'return document.documentElement.scrollTop;'))
Local $JS_Scr_Height = Json_Decode(_WD_ExecuteScript($sSession, "return screen.height;"))
Local $JS_Doc_Height = Json_Decode(_WD_ExecuteScript($sSession, "return document.body.scrollHeight;"))
Local $JS_Scr_InnerHeight = Json_Decode(_WD_ExecuteScript($sSession, "return window.innerHeight;"))

ConsoleWrite("ScrollTop " & Json_Get($JS_ScrollTop, "[value]") & @CRLF & _
  "Scr_Height " & Json_Get($JS_Scr_Height, "[value]") & @CRLF & _
  "Doc_Height " & Json_Get($JS_Doc_Height, "[value]") & @CRLF & _
  "Scr_InnerHeight " & Json_Get($JS_Scr_InnerHeight, "[value]") & @CRLF)

Local $iScrollTop = Number(Json_Get($JS_ScrollTop, "[value]"))
Local $iDocHeight = Number(Json_Get($JS_Doc_Height, "[value]"))
Local $iInnerHeight = Number(Json_Get($JS_Scr_InnerHeight, "[value]"))

If $iScrollTop + $iInnerHeight >= $iDocHeight Then MsgBox($MB_SYSTEMMODAL, "You are", "at the bottom")


Link to post
Share on other sites

@NineYou could use an array to eliminate the repeated calls to _WD_ExecuteScript --

$sScript = "return new Array(document.documentElement.scrollTop, screen.height, document.body.scrollHeight, window.innerHeight);"
$aResults = _WD_ExecuteScript($sSession, $sScript, $_WD_EmptyDict, Default, $_WD_JSON_Value)

I'm wondering if this could be done with one of the _GuiScrollBars functions.

Link to post
Share on other sites
30 minutes ago, Danp2 said:

I'm wondering if this could be done with one of the _GuiScrollBars functions.

I tried it but it doesn't work.  I do believe that the scroll bars are not standard Window elements (like pretty much everything else in Chrome).

33 minutes ago, Danp2 said:

You could use an array to eliminate the repeated calls

Thanks for the tip.  As you can see, I am not a JS wizard...

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...