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 1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 1331

PostPosted: Wed May 16, 2007 1:06 pm    Post subject: Determine if a WebPage is completely loaded in IE Reply with quote

It'll check whether a webpage is completely loaded or not in the active Internet Explorer.

NEED the latest COM Standard Library.

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
}


Last edited by Sean on Tue Jan 15, 2008 11:00 am; edited 2 times in total
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3624
Location: Belgrade

PostPosted: Wed May 16, 2007 1:12 pm    Post subject: Reply with quote

Many times asked so far. You made ppl happy now.
_________________
Back to top
View user's profile Send private message MSN Messenger
SKAN



Joined: 26 Dec 2005
Posts: 5812

PostPosted: Wed May 16, 2007 1:37 pm    Post subject: Reply with quote

Thanks Sean. I need this for a couple of scripts.

Very Happy
Back to top
View user's profile Send private message
boge



Joined: 16 May 2007
Posts: 11

PostPosted: Wed May 16, 2007 3:26 pm    Post subject: Reply with quote

very nice sean...

btw, do you have something similar for firefox?
since I work most of the time with firefox...
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Wed May 16, 2007 6:22 pm    Post subject: Reply with quote

Great work. I've added it to the FAQ:
Quote:
How to detect when a web page is finished loading?

With Internet Explorer, perhaps the most reliable method is to use DllCall and COM as demonstrated at http://www.autohotkey.com/forum/topic19256.html. On a related note, the contents of the address bar and status bar can be retrieved as demonstrated at http://www.autohotkey.com/forum/topic19255.html.
Back to top
View user's profile Send private message Send e-mail
Sean



Joined: 12 Feb 2007
Posts: 1331

PostPosted: Thu May 17, 2007 2:12 pm    Post subject: Reply with quote

Chris wrote:
Great work. I've added it to the FAQ

Thanks!
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1331

PostPosted: Thu May 17, 2007 2:14 pm    Post subject: Reply with quote

boge wrote:
btw, do you have something similar for firefox?
since I work most of the time with firefox...

Unfortunately, no. I don't know of a way with firefox.
Back to top
View user's profile Send private message
bennoman
Guest





PostPosted: Thu Jun 14, 2007 5:02 pm    Post subject: This isnt working for me Reply with quote

Im relativley new to ahk, so maybe im doing something wrong. I copied your code and created a new ahk file on my desktop. Then copied the CoHelper code and saved it as CoHelper.ahk also on my desktop. I then double click on the first file to run it and I get this error:
Error at line 64 in #include file "C:\Documents and Settings\bdmock\Desktop\CoHelper.ahk".
Line Text: :
Error: The leftmost character above is illegal in an expression.
The program will exit.

I have been charged with automating the test order process on one of my companies websites. I have started working on this already and found that the only way to have my script wait for the page to load is to use ImageSearch. This process works so far but this sounds like it will work more efficiently.
What am I doing wrong? How will this work within another script?

Thank you in advance.
Back to top
n-l-i-d
Guest





PostPosted: Thu Jun 14, 2007 6:50 pm    Post subject: Reply with quote

Just a guess: Wordwrap error while copying?
Back to top
bennoman



Joined: 14 Jun 2007
Posts: 11

PostPosted: Thu Jun 14, 2007 7:03 pm    Post subject: Reply with quote

I recopied the code for both programs and still got the same error. I tried copying the code into notepad, textpad, and word all with the same result.

Am I using it properly? Do I need to assign a hotkey to it or call it from another script? It sounds like it is supposed to throw a MsgBox when the page under the mouse is finished loading, when I start the script my mouse is on the desktop. Could this be the problem? If so, how do I start the script while the page is loading?
Back to top
View user's profile Send private message
bennoman



Joined: 14 Jun 2007
Posts: 11

PostPosted: Thu Jun 14, 2007 7:05 pm    Post subject: Reply with quote

by the way, line 64 is:

Unicode2Ansi(ByRef wString, ByRef sString, nLen = 0)
{
pString := wString + 0 > 65535 ? wString : &wString
If !nLen
nLen := DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int", 0, "Uint", 0, "Uint", 0)
VarSetCapacity(sString, nLen)
DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nLen, "Uint", 0, "Uint", 0)
}
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Thu Jun 14, 2007 7:58 pm    Post subject: Reply with quote

Next guess: Try updating your AutoHotkey to the latest version...
Back to top
bennoman



Joined: 14 Jun 2007
Posts: 11

PostPosted: Thu Jun 14, 2007 8:31 pm    Post subject: WOOT Reply with quote

That worked! I was still using the version I downloaded last year around september because I do not have admin rights on my computer so I had to call a helpdesk tech over to install the newer version.
Thank you for your help. Next time I have problems like this I will make sure Im using the current version before wasting everyones time in the forum.
Thanks again.
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Thu Jun 14, 2007 8:45 pm    Post subject: Reply with quote

No prob. You can download the zipped version of AutoHotkey too, for your portable-AutoHotkey-pleasure Wink
Back to top
bennoman



Joined: 14 Jun 2007
Posts: 11

PostPosted: Thu Jun 14, 2007 9:29 pm    Post subject: Reply with quote

Thanks Sean, this works beautifully in my scripts.
Great Job!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3, 4, 5, 6  Next
Page 1 of 6

 
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