Sign in to follow this  
Followers 0
jbg1978

IE Scrollbars

5 posts in this topic

Anyone have any success progamatically scrolling up/down in an IE window?

Share this post


Link to post
Share on other sites



Anyone have any success progamatically scrolling up/down in an IE window?

Not directly via an API. The "Internet Explorer_Server" class control's scrollbars don't seem to work with the _GuiScrollBars_* functions. But this simulates it somewhat:
#include <IE.au3>

Global $sURL = "http://www.google.com/search?q=AutoIt+site%3Aautoitscript.com&btnG=Search"
Global $oIE = _IECreate($sURL, 1)
Global $hIE = _IEPropertyGet($oIE, "hwnd")
ConsoleWrite("Debug: $hIE = " & $hIE & @LF)
WinActivate($hIE)
Global $hFrame = ControlGetHandle($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")
ConsoleWrite("Debug: $hFrame = " & $hFrame & @LF)

For $n = 1 to 6
    If Mod($n, 2) Then 
        $sKey = "{UP}"
    Else
        $sKey = "{DOWN}"
    EndIf
    For $x = 1 To 5
        ControlSend($hIE, "", $hFrame, $sKey)
        Sleep(1000)
    Next
Next

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The IE DOM does have several properties to control scrolling... there are quite a few examples in the forum... here's one: http://www.autoitscript.com/forum/index.ph...hl=scrollheight

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

As usual, Dale brings the good stuff:

Here is the magic you need:

$iDocHeight = $oIE.document.body.scrollHeight
   $oIE.document.parentwindow.scrollTo(0,$iDocHeight)
Ref (W3Schools): HTML DOM scrollTo() Method

So my demo becomes:

#include <IE.au3>

Global $sURL = "http://www.google.com/search?q=AutoIt+site%3Aautoitscript.com&btnG=Search"
Global $oIE = _IECreate($sURL, 1)
Global $iDocHeight = $oIE.document.body.scrollHeight, $iDirection, $iStart, $iY
For $n = 1 to 4
    If Mod($n, 2) Then
    ; Down
        $iDirection = 1
        $iStart = 0
        $iEnd = $iDocHeight
    Else
    ; Up
        $iDirection = -1
        $iStart = $iDocHeight
        $iEnd = 0
    EndIf
    
    For $y = $iStart To $iEnd Step Int(($iDocHeight / 3) * $iDirection)
        $oIE.document.parentwindow.scrollTo(0, $y)
        Sleep(1000)
    Next
Next

Thanks, Dale. :)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thank you. I think the scrollTo method is going to be the way to go because that's how I would do it in VB. I was experiencing troubles with that yesterday...was receiving the error The requested action with the object failed, but I think it may have been because I was trying to scroll outside of the acceptable range which it looks like your code accounts for. I will try your approach and let you know. Thank you all for the help.

Share this post


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
Sign in to follow this  
Followers 0