AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Determine if a WebPage is completely loaded in IE
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Sat Apr 18, 2009 4:02 pm    Post subject: Re: Determine if a WebPage is completely loaded in IE Reply with quote

Sean wrote:

Code:
; Run, iexplore.exe http://www.google.com/
MsgBox, % IEReady()
Return

IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      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
}
Sean, instead if using the run command I want to be able to click on a link and wait for that next page to load. I modified your script a little but it does not work.
Can you help please.
DataLife
Code:
F6::
; Run, iexplore.exe http://www.google.com/
MouseMove,300,690
Click   

MsgBox, % IEReady()
Return

IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      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
}

_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Sun Apr 26, 2009 6:35 am    Post subject: Reply with quote

I want to refresh a webpage and then use the code below to wait for the webpage to be fully loaded.

I replaced the webpage below with my webpage but it opens a new iexplore window.

I just want to refresh and monitor the current webpage.

How can I modify the code below to do that?


Code:
#Include CoHelper.ahk
F12::
send {F5}
gosub WebPageFullyLoaded
msgbox Web page is fully loaded
return

WebPageFullyLoaded:
CoInitialize()
pie := ActiveXObject("InternetExplorer.Application")
Invoke(pie, "Visible=", "True")
Invoke(pie, "Navigate", "http://foxnews.com")
Loop
{
   If   Invoke(pie, "ReadyState") = 4
      Break
   Sleep,   500
}
Release(pie)
CoUninitialize()
Return
Thanks DataLife
_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Sun Apr 26, 2009 7:39 am    Post subject: Reply with quote

DataLife wrote:
I just want to refresh and monitor the current webpage.
You already knew/obtained pweb, so just use it.
Back to top
View user's profile Send private message
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Sun Apr 26, 2009 7:39 pm    Post subject: Reply with quote

The script works very well using pweb to wait for the current page to refresh and finish loading.

I also would like to click on a link and the script tell me when it is finished loading.

Here is my code. It says done instantly after the script clicks on the Google news link.
Code:
SetTitleMatchMode, 2
F6::
WinWaitActive,Google
Click 175,130
MsgBox % IEReady()
Return



IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      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
}
Any help would be appreciated.
DataLife
_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Sun Apr 26, 2009 7:44 pm    Post subject: Reply with quote

You must first ensure navigation has begun
see below this is true when you send clicks there is a lag between the click and the point where navigation actually begins
Code:
SetTitleMatchMode, 2
F6::
WinWaitActive,Google
Click 175,130
MsgBox % IEReady()
Return



IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      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,20
         If   COM_Invoke(pweb, "ReadyState") <> 4
            Break
         Else   Sleep 500

      Loop
         If   COM_Invoke(pweb, "ReadyState") = 4
            Break
         Else   Sleep 500
   COM_Release(pdoc)
   COM_Release(pweb)
   COM_Term()
   Return   pweb ? "DONE!" : False
}

_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Sun Apr 26, 2009 8:07 pm    Post subject: Reply with quote

Perfect, works great.

Many thanks!!
DataLife
_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Thu Jun 11, 2009 1:22 am    Post subject: Reply with quote

I rewrote the script using DocumentComplete event. I suggest to test it against sites the original script used to report falsely.

Code:
#Persistent
sUrl :=   "http://www.autohotkey.com/forum/"

COM_Init()
pweb :=   COM_CreateObject("InternetExplorer.Application")
sink :=   COM_ConnectObject(pweb, "IE_")
COM_Invoke(pweb, "Visible", True)
COM_Invoke(pweb, "Navigate2", sUrl)
Return

OnComplete:
MsgBox,   DONE
COM_DisconnectObject(sink)
COM_Release(pweb)
COM_Term()
ExitApp

IE_DocumentComplete(prms, sink)
{
   If   NumGet(NumGet(prms+0)+24) = NumGet(sink+12)
      SetTimer, OnComplete, -10
/* more rigorous way
   COM_Release(punk1:=COM_QueryInterface(NumGet(NumGet(prms+0)+24),0))
   COM_Release(punk2:=COM_QueryInterface(NumGet(sink+12),0))
   If   (punk1 = punk2)
      SetTimer, OnComplete, -10
*/
}
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Sun Aug 02, 2009 4:07 am    Post subject: Reply with quote

Sean wrote:
I rewrote the script using DocumentComplete event
Thank you for this example. I haven't found any issues with your script, but I'm trying to create a function version of this concept to work with inactive IE tabs. I found a possible issue, which is if the DocumentComplete event occurs before COM_ConnectObject connects (I think). However, the only webpage I've been able to create this issue with is Yahoo.com. Here's an example of what I mean (perhaps oversimplified):
Code:
; requires already existing IE navigated to www.google.com

#Persistent
COM_Init()
If !pwb := IEGetTab("Google")
   Return
; LoadURL(pwb, "www.yahoo.com") ; Edit - could use this line instead of next 2 lines
COM_Invoke(pwb, "Navigate", "www.yahoo.com")
PageLoaded(pwb)

MsgBox DONE!

COM_Release(pwb)
COM_Term()
Return

;-------------------------------------------------------------------------------------------------
IEGetTab(name) {
   oShell := COM_CreateObject("Shell.Application")
   Loop % COM_Invoke(oShell, "Windows.Count")
      If (COM_Invoke(oShell, "Windows.item[" A_Index - 1 "].LocationName") = name
      && COM_Invoke(oShell, "Windows.item[" A_Index - 1 "].Name") = "Windows Internet Explorer")
      {   pweb := COM_Invoke(oShell, "Windows.item[" A_Index - 1 "]")
         Break
      }
   COM_Release(oShell)
   Return pweb
}

PageLoaded(pweb) {
   global webpage_loading = 1
   sink := COM_ConnectObject(pweb, "IE_")
   While webpage_loading
      Sleep 1
   COM_DisconnectObject(sink)
   Return
}


IE_DocumentComplete() {
   SetTimer, OnComplete, -10
}

OnComplete:
webpage_loading = 0
Return


; Added based off Sean's recommendation in the next post
LoadURL(pweb, URL) {
   global webpage_loading = 1
   sink := COM_ConnectObject(pweb, "IE_")
   COM_Invoke(pweb, "Navigate", URL)
   While webpage_loading
      Sleep 1
   COM_DisconnectObject(sink)
   Return
}


Edit - updated script to include the Name property, as Sean suggests in the next post. Also, added LoadURL().
_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference


Last edited by jethrow on Sun Aug 02, 2009 6:33 pm; edited 4 times in total
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Sun Aug 02, 2009 11:28 am    Post subject: Reply with quote

Time Travel has not been realized yet. There is nothing you can do about events before connected to an object. Connect first, then navigate. That's how it's supposed to work.
jethrow wrote:
This would verify the ShellWindow item is an IE window, and not a Windows Explorer window.
You may use Name or FullName property instead.
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Sun Aug 02, 2009 4:56 pm    Post subject: Reply with quote

heya good lookin work one thing
Code:
;-------------------------------------------------------------------------------------------------
IEGetTab(name) {
   oShell := COM_CreateObject("Shell.Application")
   Loop % COM_Invoke(oShell, "Windows.Count")
      If (COM_Invoke(oShell, "Windows.item[" A_Index - 1 "].LocationName") = name
      && COM_Invoke(oShell, "Windows.item[" A_Index - 1 "].Name") = "Windows Internet Explorer")
      {   pweb := COM_Invoke(oShell, "Windows.item[" A_Index - 1 "]")
         Break
      }
   COM_Release(oShell)
   Return pweb
}
I am sure you already knew and just overlooked this but the Windows Internet Explorer and Microsoft Internet Explorer suffixes do not actually come thru the LocationName property of the iWebBrowser2 object

here is my suggestion
Code:
IEGetTab(name) {
   If   oShell := COM_CreateObject("Shell.Application") {
      If   oWindows:=COM_Invoke(oShell, "Windows")   {
;~          to filter out the suffixes automatically
         StringSplit,name,name,- ; takes care of either suffix
         name=%name1% ; trim trailing spaces
         Loop,% COM_Invoke(oWindows, "Count")
            If   pweb:=InStr(COM_Invoke(oWindows, "item[" A_Index - 1 "].LocationName"),name) ? COM_Invoke(oWindows, "item", A_Index - 1) :
               break
      }
      COM_Release(oShell)
   }
   Return pweb
}

EDIT I incorrectly accused jethrow of using LocationName instead of Name. but as the result could be Windows... in IE7 or 8 it would be Microsoft .... in previous versions. This tactic would also be un necesary since the ShellWindows collection only returns WebBrowser objects
Edit Corrected a typo in my own example used name instead of LocationName
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Tue Sep 22, 2009 1:58 pm    Post subject: Reply with quote

tank wrote:
You must first ensure navigation has begun
see below this is true when you send clicks there is a lag between the click and the point where navigation actually begins
Code:
SetTitleMatchMode, 2
F6::
WinWaitActive,Google
Click 175,130
MsgBox % IEReady()
Return



IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      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,20
         If   COM_Invoke(pweb, "ReadyState") <> 4
            Break
         Else   Sleep 500

      Loop
         If   COM_Invoke(pweb, "ReadyState") = 4
            Break
         Else   Sleep 500
   COM_Release(pdoc)
   COM_Release(pweb)
   COM_Term()
   Return   pweb ? "DONE!" : False
}


I'm having issues running the code. The line that initialized pweb is not included, which does not allow the code to compile. How can we remedy this?

The big picture question is, how can we reuse this code without creating a new IE process, and just have the code find an existing IE process via searching the IE's title bar?

By the way, I've added this script to the wiki. You can find it here:
http://www.autohotkey.com/wiki/index.php?title=Determine_if_a_WebPage_is_completely_loaded_in_IE_via_COM


Last edited by ghee22 on Tue Sep 22, 2009 2:02 pm; edited 1 time in total
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Tue Sep 22, 2009 2:02 pm    Post subject: Reply with quote

huh ???????? Confused it is included
below is cute from the code you just quoted

Code:
......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}").......

_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Tue Sep 22, 2009 2:56 pm    Post subject: Reply with quote

tank wrote:
huh ???????? Confused it is included
below is cute from the code you just quoted

Code:
......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}").......


Thank you! Mistaken post, was using old code. Now I am now using Sean's latest post code and it also works with existing IE processes. It just takes the active window and works with that. Thank you.
Back to top
View user's profile Send private message
SammE
Guest





PostPosted: Sat Oct 10, 2009 10:39 pm    Post subject: Re: Determine if a WebPage is completely loaded in IE Reply with quote

Sean wrote:
It'll navigate and wait until a webpage is completely loaded in an Internet Explorer.

NEED the latest COM Standard Library.

Code:
#Persistent
sUrl :=   "http://www.autohotkey.com/forum/"

COM_Init()
pweb :=   COM_CreateObject("InternetExplorer.Application")
sink :=   COM_ConnectObject(pweb, "IE_")
COM_Invoke(pweb, "Visible", True)

bComplete := False
COM_Invoke(pweb, "Navigate2", sUrl)
While !bComplete
      Sleep, 500

COM_DisconnectObject(sink)
COM_Release(pweb)
COM_Term()
Return

OnComplete:
bComplete := True
Return

IE_DocumentComplete(prms, sink)
{
   If   NumGet(NumGet(prms+0)+24) = NumGet(sink+12)
      SetTimer, OnComplete, -10
/* more rigorous way
   COM_Release(punk1:=COM_QueryInterface(NumGet(NumGet(prms+0)+24),0))
   COM_Release(punk2:=COM_QueryInterface(NumGet(sink+12),0))
   If   (punk1 = punk2)
      SetTimer, OnComplete, -10
*/
}

IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      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}")
   {
      While,   COM_Invoke(pweb, "ReadyState") <> 4
      Sleep,   500
      While,   COM_Invoke(pweb, "document.readyState") <> "complete"
      Sleep,   500
      COM_Release(pweb)
   }
   COM_Release(pdoc)
   COM_Term()
   Return   pweb ? "DONE!" : False
}


hello....
above is Seans code.....

below is my code....

i use @ work....
can someone tell me how to include SEANs code..


Quote:
WinWait, Newtop Inc. - Windows Internet Explorer,
IfWinNotActive, Newtop Inc. - Windows Internet Explorer, , WinActivate, Newtop Inc. - Windows Internet Explorer,
WinWaitActive, Newtop Inc. - Windows Internet Explorer, (( also note that at the time the script is running i have 3 windows with the same name ))

#0::
Sleep, 100
Send, {CTRLDOWN}f{CTRLUP}
WinWait, Find,
IfWinNotActive, Find, , WinActivate, Find,
WinWaitActive, Find,
Send, copyright{ENTER}
sleep, 300
send, {ESC}
sleep, 1000
Send, {SHIFTDOWN}{TAB}
sleep, 300
send, {SHIFTDOWN}{TAB}
sleep, 300
send, {SPACE}
Sleep, 6800 <-- this is where i have the problem some windows could
take about 7 seconds to load others 10 or others
3 seconds... i need the code above to maybe
automatically know when the window finished loading
then continue on with the macro

MouseClick, left, 938, 93
MouseClick, left, 938, 93 ((this is the 3rd window with the same name))
Sleep, 1000
Send, {CTRLDOWN}c{CTRLUP} (( it copies a number from this window ))

sleep, 200
send, {ALTDOWN}{F4}{ALTUP} (( close the third window ))
Sleep, 3400
Send, {ALTDOWN}{F4}{ALTUP} (( close the second window ))

Sleep, 2400
WinWait, Newtop Inc. - Windows Internet Explorer,
IfWinNotActive, Newtop Inc. - Windows Internet Explorer, , WinActivate, Newtop Inc. - Windows Internet Explorer,
WinWaitActive, Newtop Inc. - Windows Internet Explorer,
#5::
MouseClick, left, 1256, 635
Send, c{TAB}{TAB}{SPACE}{SHIFTDOWN}{TAB}{SHIFTUP}{SPACE}
Sleep, 2000
MouseClick, left, 1255, 635
Sleep, 200
Send, p{TAB}{TAB}{SPACE}{SHIFTDOWN}{TAB}{SHIFTUP}{SPACE}
sleep, 200
MouseClick, left, 93, 206
Sleep, 200
#6::
MouseClick, left, 427, 1044
Sleep, 1000
WinWait, OrderTracking - Windows Internet Explorer,
IfWinNotActive, OrderTracking - Windows Internet Explorer, , WinActivate, OrderTracking - Windows Internet Explorer,
WinWaitActive, OrderTracking - Windows Internet Explorer,
Sleep, 1500
MouseClick, left, 1117, 744
Sleep, 1000
Send, {PGDN}{PGDN}{PGDN}{PGDN}
sleep, 800
send, {SHIFTDOWN}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{SHIFTUP}{SPACE}
sleep, 1500
send, {CTRLDOWN}v{CTRLUP}{LEFT}{LEFT}{left}{left}{left}{LEFT}{LEFT}{LEFT}{LEFT}{BACKSPACE}{BACKSPACE}{BACKSPACE}
sleep, 1500
send, {TAB}sa{TAB}{TAB}{SPACE}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{SPACE}
sleep, 100
return



thank you very very much for looking into it
and modyfing my code so it does
what i want it to do...
Back to top
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Sun Oct 11, 2009 2:05 pm    Post subject: Re: Determine if a WebPage is completely loaded in IE Reply with quote

SammE wrote:
Sean wrote:
It'll navigate and wait until a webpage is completely loaded in an Internet Explorer.

NEED the latest COM Standard Library.

Code:
#Persistent
sUrl :=   "http://www.autohotkey.com/forum/"

COM_Init()
pweb :=   COM_CreateObject("InternetExplorer.Application")
sink :=   COM_ConnectObject(pweb, "IE_")
COM_Invoke(pweb, "Visible", True)

bComplete := False
COM_Invoke(pweb, "Navigate2", sUrl)
While !bComplete
      Sleep, 500

COM_DisconnectObject(sink)
COM_Release(pweb)
COM_Term()
Return

OnComplete:
bComplete := True
Return

IE_DocumentComplete(prms, sink)
{
   If   NumGet(NumGet(prms+0)+24) = NumGet(sink+12)
      SetTimer, OnComplete, -10
/* more rigorous way
   COM_Release(punk1:=COM_QueryInterface(NumGet(NumGet(prms+0)+24),0))
   COM_Release(punk2:=COM_QueryInterface(NumGet(sink+12),0))
   If   (punk1 = punk2)
      SetTimer, OnComplete, -10
*/
}

IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      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}")
   {
      While,   COM_Invoke(pweb, "ReadyState") <> 4
      Sleep,   500
      While,   COM_Invoke(pweb, "document.readyState") <> "complete"
      Sleep,   500
      COM_Release(pweb)
   }
   COM_Release(pdoc)
   COM_Term()
   Return   pweb ? "DONE!" : False
}


hello....
above is Seans code.....

below is my code....

i use @ work....
can someone tell me how to include SEANs code..


Code:
WinWait, Newtop Inc. - Windows Internet Explorer,
IfWinNotActive, Newtop Inc. - Windows Internet Explorer, , WinActivate, Newtop Inc. - Windows Internet Explorer,
WinWaitActive, Newtop Inc. - Windows Internet Explorer, (( also note that at the time the script is running i have 3 windows with the same name ))

#0::
Sleep, 100
Send, {CTRLDOWN}f{CTRLUP}
WinWait, Find,
IfWinNotActive, Find, , WinActivate, Find,
WinWaitActive, Find,
Send, copyright{ENTER}
sleep, 300
send, {ESC}
sleep, 1000
Send, {SHIFTDOWN}{TAB}
sleep, 300
send, {SHIFTDOWN}{TAB}
sleep, 300
send, {SPACE}
Sleep, 6800    <-- this is where i have the problem some     windows could
                       take about 7 seconds to load others 10 or others 
                          3 seconds... i need the code above to maybe
                          automatically know when the window finished loading
                          then continue on with the macro

MouseClick, left,  938,  93
MouseClick, left,  938,  93  ((this is the 3rd window with the same name))
Sleep, 1000
Send, {CTRLDOWN}c{CTRLUP}  (( it copies a number from this window ))

sleep, 200
send, {ALTDOWN}{F4}{ALTUP}  (( close the third window ))
Sleep, 3400
Send, {ALTDOWN}{F4}{ALTUP}    (( close the second window ))

Sleep, 2400
WinWait, Newtop Inc. - Windows Internet Explorer,
IfWinNotActive, Newtop Inc. - Windows Internet Explorer, , WinActivate, Newtop Inc. - Windows Internet Explorer,
WinWaitActive, Newtop Inc. - Windows Internet Explorer,
#5::
MouseClick, left,  1256,  635
Send, c{TAB}{TAB}{SPACE}{SHIFTDOWN}{TAB}{SHIFTUP}{SPACE}
Sleep, 2000
MouseClick, left,  1255,  635
Sleep, 200
Send, p{TAB}{TAB}{SPACE}{SHIFTDOWN}{TAB}{SHIFTUP}{SPACE}
sleep, 200
MouseClick, left,  93,  206
Sleep, 200
#6::
MouseClick, left,  427,  1044
Sleep, 1000
WinWait, OrderTracking - Windows Internet Explorer,
IfWinNotActive, OrderTracking - Windows Internet Explorer, , WinActivate, OrderTracking - Windows Internet Explorer,
WinWaitActive, OrderTracking - Windows Internet Explorer,
Sleep, 1500
MouseClick, left,  1117,  744
Sleep, 1000
Send, {PGDN}{PGDN}{PGDN}{PGDN}
sleep, 800
send, {SHIFTDOWN}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{SHIFTUP}{SPACE}
sleep, 1500
send, {CTRLDOWN}v{CTRLUP}{LEFT}{LEFT}{left}{left}{left}{LEFT}{LEFT}{LEFT}{LEFT}{BACKSPACE}{BACKSPACE}{BACKSPACE}
sleep, 1500
send, {TAB}sa{TAB}{TAB}{SPACE}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{SPACE}
sleep, 100
return



thank you very very much for looking into it
and modyfing my code so it does
what i want it to do...


I removed everything except IE_Ready() and added a function, Wait_for_IE(). Here's my version of Sean's modified code:
Code:
Wait_for_IE(IE_title) {
SetTitleMatchMode, 2
WinWaitActive,%IE_title%
IEReady()
SetTitleMatchMode, RegEx
}

IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      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}")
   {
      While,   COM_Invoke(pweb, "ReadyState") <> 4
      Sleep,   500
      While,   COM_Invoke(pweb, "document.readyState") <> "complete"
      Sleep,   500
      COM_Release(pweb)
   }
   COM_Release(pdoc)
   COM_Term()
   Return   pweb ? "DONE!" : False
}


To wait for a certain window to load, I call the function I added like so:
Code:
Wait_for_IE("Title of IE window to wait for")


Hence, with my modified version, I would replace your code:
Code:
WinWait, OrderTracking - Windows Internet Explorer,
IfWinNotActive, OrderTracking - Windows Internet Explorer, , WinActivate, OrderTracking - Windows Internet Explorer,
WinWaitActive, OrderTracking - Windows Internet Explorer,

with this code:
Code:
Wait_for_IE(" OrderTracking - Windows Internet Explorer")
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Page 7 of 8

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group