Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Determine if a WebPage is completely loaded in IE


  • Please log in to reply
75 replies to this topic
ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006
That still does not work for me.
The first loop never breaks.
Posted Image
ʞɔпɟ əɥʇ ʇɐɥʍ

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

That still does not work for me.
The first loop never breaks.

This is what lexikos said, invoking "ReadyState" on wrong pie. Please run the script I linked how many pages/windows of IE are running after "Navigate".

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006
I get this:

---------------------------
IEJS.AHK
---------------------------
1180506 : "","","","Windows Internet Explorer","C:\Program Files\Internet Explorer\iexplore.exe"
: "","","","",""
: "","","","",""
: "","","","",""
: "","","","",""
: "","","","",""
: "","","","",""
5047356 : "","","","Windows Internet Explorer","C:\Program Files\Internet Explorer\iexplore.exe"
591834 : "","","Website found. Waiting for reply...","Windows Internet Explorer","C:\Program Files\Internet Explorer\iexplore.exe"

---------------------------
OK
---------------------------



With this:
^F1::
MsgBox, % "Pie " . LoadIEDone("http://www.google.com")
return



LoadIEDone(URL_TO_LOAD)
{
com_CoInitialize()
pie := com_ActiveXObject("InternetExplorer.Application")
com_Invoke(pie, "Visible=", True)
com_Invoke(pie, "Navigate", URL_TO_LOAD)
psh :=   COM_CreateObject("Shell.Application")
psw :=   COM_Invoke(psh, "Windows")
Loop, %   COM_Invoke(psw, "Count")
   pwb := COM_Invoke(psw, "Item", A_Index-1), sInfo .= COM_Invoke(pwb, "hWnd") . " : """ . COM_Invoke(pwb, "LocationURL") . """,""" . COM_Invoke(pwb, "LocationName") . """,""" . COM_Invoke(pwb, "StatusText") . """,""" . COM_Invoke(pwb, "Name") . """,""" . COM_Invoke(pwb, "FullName") . """`n", COM_Release(pwb)
COM_Release(psw)
COM_Release(psh)
;COM_Term()

MsgBox, % sInfo

Loop
   If   pdoc:=Com_Invoke(pie, "Document")
        Break
   Else Sleep 100
Loop
   If   Com_Invoke(pdoc, "readyState") = "complete"
        Break
   Else Sleep 500
Com_Release(pdoc)

com_Release(pie)
com_CoUninitialize()
return pie
}

Posted Image
ʞɔпɟ əɥʇ ʇɐɥʍ

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

I get this:

---------------------------
IEJS.AHK
---------------------------
1180506 : "","","","Windows Internet Explorer","C:\Program Files\Internet Explorer\iexplore.exe"
: "","","","",""
: "","","","",""
: "","","","",""
: "","","","",""
: "","","","",""
: "","","","",""
5047356 : "","","","Windows Internet Explorer","C:\Program Files\Internet Explorer\iexplore.exe"
591834 : "","","Website found. Waiting for reply...","Windows Internet Explorer","C:\Program Files\Internet Explorer\iexplore.exe"

---------------------------
OK
---------------------------

So, the linked script seemed to work, at least partially as there exist lots of blank ones too. I was worried it also might not work in Vista.

Which one the web page is actually loading in? Is it the same one as the original pie or not?
MsgBox, % pie . " | hWnd: " . COM_Invoke(pie, "hWnd")
Anyway, now it may be a matter of picking the corrected one where the wanted web page is loading that I can't do from here.

Erittaf
  • Members
  • 192 posts
  • Last active: Feb 28 2013 11:49 PM
  • Joined: 02 Nov 2007

591834 : "","","Website found. Waiting for reply...","Windows Internet Explorer","C:\Program Files\Internet Explorer\iexplore.exe"

I would think that the window/pie we want is this one. Could we loop through these windows and reliably pick out the wanted window by statusbar text containing something? Would that be a reliable way to go? It's silly how much harder this appears in Vista!

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

591834 : "","","Website found. Waiting for reply...","Windows Internet Explorer","C:\Program Files\Internet Explorer\iexplore.exe"

I would think that the window/pie we want is this one.

Then, you may use this:
LoadIEDone(URL_TO_LOAD)
{
COM_Init()
pie := COM_ActiveXObject("InternetExplorer.Application")
COM_Invoke(pie, "Visible=", True)
COM_Invoke(pie, "Navigate", URL_TO_LOAD)
COM_Release(pie)
pie := 0

psh :=  COM_CreateObject("Shell.Application")
psw :=  COM_Invoke(psh, "Windows")
Loop, % COM_Invoke(psw, "Count")
{
        pwb :=  COM_Invoke(psw, "Item", A_Index-1)
        If      COM_Invoke(pwb, "Name") = "Windows Internet Explorer"
        &&      COM_Invoke(pwb, "StatusText") = "Website found. Waiting for reply..."
        {
                pie := pwb
                Break
        }
        Else    COM_Release(pwb)
}
COM_Release(psw)
COM_Release(psh)

If      pie
        Loop
                If      COM_Invoke(pie, "ReadyState") = 4
                        Break
                Else    Sleep 500
COM_Release(pie)
COM_Term()
Return  pie
}
One thing though. The StatusText may be varying, so may be needed some fine-tuning.

Erittaf
  • Members
  • 192 posts
  • Last active: Feb 28 2013 11:49 PM
  • Joined: 02 Nov 2007
might there be a way to check for status text containing anything?? from the looks of it the window we want is the only one that has any status text.

Also, For what I need I know what website I am send the browser to. Is there a way to do something like (psuedocode)
COM_Invoke(pwb, "addressBar") = "SomeSiteWeAreGoingTo"

Pooisble??

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Also, For what I need I know what website I am send the browser to. Is there a way to do something like (psuedocode)

COM_Invoke(pwb, "addressBar") = "SomeSiteWeAreGoingTo"

I don't really know about that, however, I'm a bit skeptical about it. Haven't you tried it? Anyway, there were two observations from the result of ahklerner. One is what you said: only the needed one has a status text. If it's consistently so, you may simply use
COM_Invoke(pwb, "StatusText")
instead of
COM_Invoke(pwb, "StatusText") = "Website found. Waiting for reply..."
The other one is: the result appeared somehow chronologically. If it always is, the first loop may not be needed, could simply replace it as
pie := COM_Invoke(psw, "Item", COM_Invoke(psw, "Count") - 1)


Erittaf
  • Members
  • 192 posts
  • Last active: Feb 28 2013 11:49 PM
  • Joined: 02 Nov 2007
sorry, no I haven't tried it... No vista box :-(

Thanks for the info, will write some tests and try them at work or something. Thanks!

Aamir
  • Guests
  • Last active:
  • Joined: --
Thanks Sean for the code. :D

I wan to ask whether the code works equally well for AVANT browser
http://www.avantbrowser.com/

This browser uses Internet Explorer's engine.

Erittaf
  • Members
  • 192 posts
  • Last active: Feb 28 2013 11:49 PM
  • Joined: 02 Nov 2007
Well I have a Vista box now and after helping with another related thread Lexikos pointed me at the answer for the vista problem. After playing with it some more it seems that the difference is in how long it takes for vista to load. It never got there in time on my system. However if you modify one of the two lines noted in the code below you can tweak how long it takes before timing out and throwing the error. (I just set the first one to 500 since the loop breaks when the page actually finishes loading... it doesn't take up too much extra on the resources, at least not in vista terms.)

Happy coding!


IEReady(hIESvr = 0) 
{ 
   If Not   hIESvr 
   { 
      Loop,   50                       ;<-------------modify this line!!
      { 
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame 
         If   hIESvr 
            Break
         Else   Sleep 100            ;<-------------or modify this line!!
      } 
      If Not   hIESvr 
         Return   """Internet Explorer_Server"" Not Found." 
   } 
   Else 
   { 
      WinGetClass, sClass, ahk_id %hIESvr% 
      If Not   sClass == "Internet Explorer_Server" 
         Return   "The specified control is not ""Internet Explorer_Server""." 
   } 

   COM_Init() 
   If   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult) 
   &&   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)=0 
   &&   pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}") 
      Loop 
         If   COM_Invoke(pweb, "ReadyState") = 4 
            Break 
         Else   Sleep 500 
   COM_Release(pdoc) 
   COM_Release(pweb) 
   COM_Term() 
   Return   pweb ? "DONE!" : False 
} 


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
If you change "Loop, 50" to "Loop", it will never time out. It isn't "the vista problem", but "the slow PC problem." :p

Erittaf
  • Members
  • 192 posts
  • Last active: Feb 28 2013 11:49 PM
  • Joined: 02 Nov 2007
lol, true enough. Maybe I need to increase my Precision-O-Meter :?

Mike"
  • Guests
  • Last active:
  • Joined: --
Thanks Sean.
This seems really great.
Is it possible to use Invoke() to change size of IE window ?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Why not just use WinMove? I suppose you could invoke the Width and Height properties of the WebBrowser/IE object...