 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
new one Guest
|
Posted: Mon Nov 09, 2009 5:02 pm Post subject: Waiting for a webpage to load |
|
|
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 |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Nov 09, 2009 5:26 pm Post subject: |
|
|
| most likely - do you have an example? |
|
| Back to top |
|
 |
new one Guest
|
Posted: Mon Nov 09, 2009 10:04 pm Post subject: well... |
|
|
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)? |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Mon Nov 09, 2009 10:32 pm Post subject: |
|
|
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? _________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
new one Guest
|
Posted: Tue Nov 10, 2009 3:59 pm Post subject: ok |
|
|
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
} |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Tue Nov 10, 2009 5:58 pm Post subject: |
|
|
I'm gonna take a shot in the dark and say you're not experienced with COM, right?
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: | Code: | sUrl := "http://www.gmail.com" ; first webpage to load
sUrl2 := "www.google.com" ; second webpage to load
Name := "UserName"
PW := "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", sUrl) ; navigates to the URL
; the next 2 lines wait for the webpage to be loaded. (NOTE - you could also use Sean's IEReady() 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.Email.Value", Name) ; NOTE - the red items are specific to the webpage
COM_Invoke(pweb, "document.all.Passwd.Value", PW)
; COM_Invoke(pweb, "document.all.signIn.click") ; this line would click the "Sign In" button
MsgBox, Webpage Loaded
COM_Invoke(pweb, "Navigate2", sUrl2, 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 ). 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. _________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Last edited by jethrow on Thu Nov 12, 2009 3:14 am; edited 1 time in total |
|
| Back to top |
|
 |
Astrognaw
Joined: 27 Mar 2009 Posts: 26
|
Posted: Wed Nov 11, 2009 1:23 am Post subject: |
|
|
For some reason the above code doesn't work for me in IE7.
| Code: | 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?). |
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Wed Nov 11, 2009 3:50 pm Post subject: |
|
|
Tested, works for me.
(IE8, WinXP) _________________ "Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried."
Antonio França
My stuff: Google Profile |
|
| Back to top |
|
 |
Astrognaw
Joined: 27 Mar 2009 Posts: 26
|
Posted: Wed Nov 11, 2009 11:08 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
vista_player Guest
|
Posted: Fri Nov 13, 2009 3:12 pm Post subject: I have to cope with the same problem in vista |
|
|
| I have to cope with the same problem in vista, as I tried this... How do you get over this? |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
|
| Back to top |
|
 |
poetbox
Joined: 07 Jan 2007 Posts: 107
|
Posted: Wed Dec 16, 2009 4:28 am Post subject: |
|
|
| jethrow wrote: | I'm gonna take a shot in the dark and say you're not experienced with COM, right?
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: | Code: | sUrl := "http://www.gmail.com" ; first webpage to load
sUrl2 := "www.google.com" ; second webpage to load
Name := "UserName"
PW := "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", sUrl) ; navigates to the URL
; the next 2 lines wait for the webpage to be loaded. (NOTE - you could also use Sean's IEReady() 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.Email.Value", Name) ; NOTE - the red items are specific to the webpage
COM_Invoke(pweb, "document.all.Passwd.Value", PW)
; COM_Invoke(pweb, "document.all.signIn.click") ; this line would click the "Sign In" button
MsgBox, Webpage Loaded
COM_Invoke(pweb, "Navigate2", sUrl2, 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 ). 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.
[/img] |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|