Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Waiting for a webpage to load


  • Please log in to reply
11 replies to this topic
new one
  • Guests
  • Last active:
  • Joined: --
Hi there

I have tried the solution offered at www.autohotkey.com/forum/topic19256.html

The thing is that the webpage is opened in a new explorer window and not in a new tab as I want. is there anyway to change this?

thanks

  • Guests
  • Last active:
  • Joined: --
most likely - do you have an example?

new one
  • Guests
  • Last active:
  • Joined: --
Sorry if I am not clear , but I want to open a webpage (lets say Gmail) , and wait for it to load in order to continue and enter username&password. in order to do that I 've read the suggestion at www.autohotkey.com/forum/topic19256.html. I am trying to put the suggested lines in my script. The thing is that the explorer window is open in a new window, and not in a new tab (like pressing ctrl+t in explorer) which is what I want...

what should be my script stracture?, 1.gmail, 2.put the suggested script which makes it wait to load, and then 3. continue with another lines (enter username&password)?

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
I'm seeing 2 different questions, the first being how to open the webpage in a new tab rather than a new window. How are you opening this webpage? Clicking a link? Using th Run command? Are you using Internet Explorer & COM, as Sean's thread shows? What do you have so far for code?

new one
  • Guests
  • Last active:
  • Joined: --
well , I guess the confusion arrise mostly because I am not used to run this script. I have understand that in order to run a webpage and wait for it to load I have to run sean script ( just change the webpage adress in sUrl line at the begining of the script)...

so far I have loaded a webpage (google for example) by the simple command : run www.google.com. then a new tab in internet explorer (in an explorer window which was already opened) is loaded.

when I am running sean script , a webpage is loaded in a new explorer window... all i do is running this: (maybe I need to do something else?)

#Persistent
sUrl := "http://www.gmail.com"

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
}

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
I'm gonna take a shot in the dark and say you're not experienced with COM, right? :wink:

Sean's example uses the DocumentComplete event; however, for simplicity, I'm going to use the ReadyState (or Busy - noted in comments) property. (if the previous sentence doesn't make sense right now, don't worry, it doesn't matter) Here is an example:
[color=darkred]sUrl[/color] := "http://www.gmail.com" ; first webpage to load
[color=darkred]sUrl2[/color] := "www.google.com" ; second webpage to load
[color=darkred]Name[/color] := "UserName"
[color=darkred]PW[/color] := "Password"

COM_Init() ; initializes COM environment
pweb := COM_CreateObject("InternetExplorer.Application") ; creates IE
COM_Invoke(pweb, "Visible", True) ; makes IE visible
COM_Invoke(pweb, "Navigate2", [color=darkred]sUrl[/color]) ; navigates to the URL

; the next 2 lines wait for the webpage to be loaded. (NOTE - you could also use Sean's [color=olive]IEReady()[/color] function instead of the next 2 lines)
While, COM_Invoke(pweb, "ReadyState") <> 4 ; While, COM_Invoke(pweb, "Busy")
	Sleep, 10
	
; the next two lines fill in the UserName & Password, but they also prove the WebPage is loaded (otherwise they would cause a COM ERROR)
COM_Invoke(pweb, "document.all.[color=red]Email[/color].Value", [color=darkred]Name[/color]) ; NOTE - the [color=red]red[/color] items are specific to the webpage
COM_Invoke(pweb, "document.all.[color=red]Passwd[/color].Value", [color=darkred]PW[/color])
; COM_Invoke(pweb, "document.all.signIn.click") ; this line would click the "Sign In" button
MsgBox, Webpage Loaded

COM_Invoke(pweb, "Navigate2", [color=darkred]sUrl2[/color], 0x0800) ; 0x0800 parameter causes this webpage to be opened in a new tab

COM_Release(pweb) ; releases "pweb" - COM Object
COM_Term() ; terminates COM environment
Return

If this looks like a bunch of jibberish to you, I wouldn't be surprised (it would have to me :wink:). However, IMO this is the best way to answer your question in one post. I would recommend studying Sean's thread, this example, & other COM examples in the forum.

Astrognaw
  • Members
  • 26 posts
  • Last active: Dec 02 2009 05:38 PM
  • Joined: 27 Mar 2009
For some reason the above code doesn't work for me in IE7.

COM_Invoke(pweb, "Visible", True) ; creates a blank IE7 window
COM_Invoke(pweb, "Navigate2", sUrl) ; creates a new IE7 window for sUrl and with a different pweb value.

So I basically have to find the the new "pweb" and then the ReadyState/Value functions will work.. It's odd because the first Navigate2 function is sent to the first pweb, but opens a new window. However, the second Navigate2 function is sent to the 2nd pweb and it doesn't open a new window as the first does. The same happens with plain old Navigate.

Not sure if that makes sense, nor why it's happening.

Edit: I'm using Vista on this machine, however I know I've had similar code working on XP on other machines. So it might be either my IE7 settings (I reset them to default, same problem) or my OS (likely?).

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Tested, works for me.
(IE8, WinXP)

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Astrognaw
  • Members
  • 26 posts
  • Last active: Dec 02 2009 05:38 PM
  • Joined: 27 Mar 2009
I'm simply wondering why it wouldn't work on my machine/setup. Visible creates a blank IE. Navigate2/Navigate (for that 'identity') opens a 2nd window with a different object 'identity.' I can make it work, regardless. I was wondering why this doesn't work. It seems like it ought to.

vista_player
  • Guests
  • Last active:
  • Joined: --
I have to cope with the same problem in vista, as I tried this... How do you get over this?

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
See if this thread answers your question: running COM commands on vista

poetbox
  • Members
  • 113 posts
  • Last active: Sep 11 2013 08:05 AM
  • Joined: 07 Jan 2007

I'm gonna take a shot in the dark and say you're not experienced with COM, right? :wink:

Sean's example uses the DocumentComplete event; however, for simplicity, I'm going to use the ReadyState (or Busy - noted in comments) property. (if the previous sentence doesn't make sense right now, don't worry, it doesn't matter) Here is an example:

[color=darkred]sUrl[/color] := "http://www.gmail.com" ; first webpage to load
[color=darkred]sUrl2[/color] := "www.google.com" ; second webpage to load
[color=darkred]Name[/color] := "UserName"
[color=darkred]PW[/color] := "Password"

COM_Init() ; initializes COM environment
pweb := COM_CreateObject("InternetExplorer.Application") ; creates IE
COM_Invoke(pweb, "Visible", True) ; makes IE visible
COM_Invoke(pweb, "Navigate2", [color=darkred]sUrl[/color]) ; navigates to the URL

; the next 2 lines wait for the webpage to be loaded. (NOTE - you could also use Sean's [color=olive]IEReady()[/color] function instead of the next 2 lines)
While, COM_Invoke(pweb, "ReadyState") <> 4 ; While, COM_Invoke(pweb, "Busy")
	Sleep, 10
	
; the next two lines fill in the UserName & Password, but they also prove the WebPage is loaded (otherwise they would cause a COM ERROR)
COM_Invoke(pweb, "document.all.[color=red]Email[/color].Value", [color=darkred]Name[/color]) ; NOTE - the [color=red]red[/color] items are specific to the webpage
COM_Invoke(pweb, "document.all.[color=red]Passwd[/color].Value", [color=darkred]PW[/color])
; COM_Invoke(pweb, "document.all.signIn.click") ; this line would click the "Sign In" button
MsgBox, Webpage Loaded

COM_Invoke(pweb, "Navigate2", [color=darkred]sUrl2[/color], 0x0800) ; 0x0800 parameter causes this webpage to be opened in a new tab

COM_Release(pweb) ; releases "pweb" - COM Object
COM_Term() ; terminates COM environment
Return

If this looks like a bunch of jibberish to you, I wouldn't be surprised (it would have to me :wink:). However, IMO this is the best way to answer your question in one post. I would recommend studying Sean's thread, this example, & other COM examples in the forum.

ERROR to click the button.
Posted Image[/img]