AutoHotkey Community

It is currently May 25th, 2012, 5:34 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 119 posts ]  Go to page 1, 2, 3, 4, 5 ... 8  Next
Author Message
PostPosted: May 16th, 2007, 1:06 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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
}


Last edited by Sean on June 27th, 2009, 2:57 am, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2007, 1:12 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Many times asked so far. You made ppl happy now.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2007, 1:37 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Thanks Sean. I need this for a couple of scripts.

:D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2007, 3:26 pm 
Offline

Joined: May 16th, 2007, 3:24 pm
Posts: 11
very nice sean...

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2007, 6:22 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 17th, 2007, 2:12 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Chris wrote:
Great work. I've added it to the FAQ

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 17th, 2007, 2:14 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: This isnt working for me
PostPosted: June 14th, 2007, 5:02 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2007, 6:50 pm 
Just a guess: Wordwrap error while copying?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2007, 7:03 pm 
Offline

Joined: June 14th, 2007, 6:43 pm
Posts: 11
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2007, 7:05 pm 
Offline

Joined: June 14th, 2007, 6:43 pm
Posts: 11
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)
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2007, 7:58 pm 
Next guess: Try updating your AutoHotkey to the latest version...


Report this post
Top
  
Reply with quote  
 Post subject: WOOT
PostPosted: June 14th, 2007, 8:31 pm 
Offline

Joined: June 14th, 2007, 6:43 pm
Posts: 11
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2007, 8:45 pm 
No prob. You can download the zipped version of AutoHotkey too, for your portable-AutoHotkey-pleasure :wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2007, 9:29 pm 
Offline

Joined: June 14th, 2007, 6:43 pm
Posts: 11
Thanks Sean, this works beautifully in my scripts.
Great Job!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 119 posts ]  Go to page 1, 2, 3, 4, 5 ... 8  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], ZeLen1y and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group