Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Wait until site has finished loading?


  • Please log in to reply
19 replies to this topic
thegoat54
  • Members
  • 3 posts
  • Last active: Nov 09 2011 06:25 PM
  • Joined: 08 Nov 2011
Does anyone have any ideas about how I can make AHK wait until FireFox finishes loading a page before proceeding?

I tried the WinExist but the title of the window comes up before the site finishes downloading.

Can AHK wait until firefox fully loads a site before going to the next action?

Thanks!

Fo-

Honest Abe
  • Members
  • 310 posts
  • Last active: Jan 08 2015 08:56 PM
  • Joined: 07 Jan 2011
WinWait

Win7 (x64)
Look up commands faster by using the AutoHotkey Help File's index.
Start→AllPrograms→AutoHotkey→AutoHotkey Help File


Grendahl
  • Members
  • 416 posts
  • Last active: Jul 07 2014 08:01 PM
  • Joined: 10 Aug 2009
WinWait won't work for what the OP wants...


I know that there's a lot of info on doing this in Internet Explorer, and I remember even seeing some mentions of how to alter the IE method for use with FireFox.

The basics to help you begin your search, are that it's a COM method.
Always have your scripts when you need them with Dropbox.
Sign up for free! http://db.tt/9Hrieqj

Honest Abe
  • Members
  • 310 posts
  • Last active: Jan 08 2015 08:56 PM
  • Joined: 07 Jan 2011

WinWait won't work for what the OP wants...


I tested it and it works.

Win7 (x64)
Look up commands faster by using the AutoHotkey Help File's index.
Start→AllPrograms→AutoHotkey→AutoHotkey Help File


Grendahl
  • Members
  • 416 posts
  • Last active: Jul 07 2014 08:01 PM
  • Joined: 10 Aug 2009
WinWait looks for the window to exist... not for the page to fully load. On a slow connection or a slow loading site, WinWait will find the window long before the page is loaded. :wink:

Waits until the specified window exists.


Always have your scripts when you need them with Dropbox.
Sign up for free! http://db.tt/9Hrieqj

  • Guests
  • Last active:
  • Joined: --

WinWait won't work for what the OP wants...
...
The basics to help you begin your search, are that it's a COM method.

It's not what the OP asked either. :wink:

Honest Abe
  • Members
  • 310 posts
  • Last active: Jan 08 2015 08:56 PM
  • Joined: 07 Jan 2011
Try adding
sleep, 2000
after your winwait.

Increase as needed.

Win7 (x64)
Look up commands faster by using the AutoHotkey Help File's index.
Start→AllPrograms→AutoHotkey→AutoHotkey Help File


dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
It is rather inelegant, but he could use ImageSearch to determine when the reload button appears in the browser. In Firefox that means the page is done loading.
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Grendahl
  • Members
  • 416 posts
  • Last active: Jul 07 2014 08:01 PM
  • Joined: 10 Aug 2009
Edited: See Jethrow's post below containing the currently correct method of doing this. (this post left for reference)



Taken from the following thread:http://www.autohotkey.com/forum/viewtopic.php?t=41447&postdays=0&postorder=asc&highlight=firefox+load&start=30


Code (Collapse):
Run, Firefox.exe "www.google.com"
WinWaitActive, ahk_class MozillaWindowClass

MouseGetPos, x, y, win
WinGetClass, class, ahk_id %win%
if (class = "MozillaWindowClass")
   MouseMove, 0, 0, 0
while, FF4StatusBarText()
   sleep, 10

MsgBox, Page Loaded


FF4StatusBarText(hwnd="") {
   WinGet, hwnd, id, % hwnd? "ahk_id" hwnd:"ahk_class MozillaWindowClass"
   Win := Acc_ObjectFromWindow(hwnd)
   Loop, % Win.accChildCount
   {} until, GetRoleText(Win.accRole(n:=A_Index))= "property page"
   Loop, % (PropPage:=Win.accChild(n)).accChildCount
      if (GetRoleText(PropPage.accRole(A_Index)) = "status bar")
         return, PropPage.accName(A_Index)
}
GetRoleText(nRole) { ; based on Sean's function from the original ACC Library
   nSize := DllCall("oleacc\GetRoleTextW", "Uint", nRole, "Uint", 0, "Uint", 0)
   VarSetCapacity(sRole, nSize*2)
   DllCall("oleacc\GetRoleTextW", "Uint", nRole, "str", sRole, "Uint", nSize+1)
   Return   sRole
}
Note - this example uses AutoHotkey_L & the ComUtils Libraries


Always have your scripts when you need them with Dropbox.
Sign up for free! http://db.tt/9Hrieqj

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Please don't misquote Sean. Also, the above example only requires the Acc Library now. Additionally, I added Acc_GetRoleText, so the example becomes:

Run, Firefox.exe "www.google.com"
WinWaitActive, ahk_class MozillaWindowClass

MouseGetPos, x, y, win
WinGetClass, class, ahk_id %win%
if (class = "MozillaWindowClass")
   MouseMove, 0, 0, 0
while, FF4StatusBarText()
   sleep, 10

MsgBox, Page Loaded

FF4StatusBarText(hwnd="") {
	WinGet, hwnd, id, % hwnd? "ahk_id" hwnd:"ahk_class MozillaWindowClass"
	Win := Acc_ObjectFromWindow(hwnd)
	Loop, % Win.accChildCount
	{} until, Acc_GetRoleText(Win.accRole(n:=A_Index))= "property page"
	Loop, % (PropPage:=Win.accChild(n)).accChildCount
		if (Acc_GetRoleText(PropPage.accRole(A_Index)) = "status bar")
			return, PropPage.accName(A_Index)
}


Grendahl
  • Members
  • 416 posts
  • Last active: Jul 07 2014 08:01 PM
  • Joined: 10 Aug 2009
Thank you Jethrow, I didn't catch that it was your post, and that you'd quoted Sean.

I was simply trying to get the point across to Honest Abe that there is actually a way to wait for page load, and not just window load in Firefox.

(Edited the mis-quote)
Always have your scripts when you need them with Dropbox.
Sign up for free! http://db.tt/9Hrieqj

LazyMan
  • Members
  • 587 posts
  • Last active: Oct 21 2014 05:13 PM
  • Joined: 17 Feb 2011
Sometimes (maybe 10%?) FF4StatusBarText gives me the first or both of the following:

Error: 0x80070057 - The parameter is incorrect.

Source: (null)
Description: (null)
HelpFile: (null)
HelpContext: 0

Specifically: accRole

Line#
963: SendInput,!fk
964: Return
969: {
970: WinGet,HWnd,ID,HWnd ? "ahk_id " HWnd : "ahk_class MozillaWindowClass"
971: Win := Acc_ObjectFromWindow(HWnd)
972: Loop,Win.accChildCount
973: {
---> 974: }
974: Until,Acc_GetRoleText(Win.accRole(n := A_Index)) = "property page"
975: Loop,(PropPage := Win.accChild(n)).accChildCount
976: if ( Acc_GetRoleText(PropPage.accRole(A_Index)) = "status bar" )
977: Return,PropPage.accName(A_Index)
978: }
985: Run,%Firefox% -new-window <!-- m -->http://mail.google.com/mail/?kbd=1<!-- m -->
986: WinWaitActive,Gmail - Inbox ahk_class MozillaWindowClass

Continue running the script?
---------------------------
Yes No
---------------------------

Error: 0x80070057 - The parameter is incorrect.

Source: (null)
Description: (null)
HelpFile: (null)
HelpContext: 0

Specifically: accChild

Line#
969: {
970: WinGet,HWnd,ID,HWnd ? "ahk_id " HWnd : "ahk_class MozillaWindowClass"
971: Win := Acc_ObjectFromWindow(HWnd)
972: Loop,Win.accChildCount
973: {
974: }
974: Until,Acc_GetRoleText(Win.accRole(n := A_Index)) = "property page"
---> 975: Loop,(PropPage := Win.accChild(n)).accChildCount
976: if ( Acc_GetRoleText(PropPage.accRole(A_Index)) = "status bar" )
977: Return,PropPage.accName(A_Index)
978: }
985: Run,%Firefox% -new-window <!-- m -->http://mail.google.com/mail/?kbd=1<!-- m -->
986: WinWaitActive,Gmail - Inbox ahk_class MozillaWindowClass
987: WinGet,FF_Handle,ID,A
988: WinMove,ahk_id %FF_Handle%,,(A_ScreenWidth - FF_CAWd_Width) // 2,(A_ScreenHeight - FF_CAWd_Height) // 2,FF_CAWd_Width,FF_CAWd_Height

Continue running the script?
---------------------------
Yes No
---------------------------

I am using Windows XP SP3, AHK_L 1.1.05.01, and:

Run %Firefox% -new-window http://mail.google.com/mail/?kbd=1
   WinWaitActive Gmail - Inbox ahk_class MozillaWindowClass
   WinGet FF_Handle, ID, A
   WinMove ahk_id %FF_Handle%, , (A_ScreenWidth - FF_CAWd_Width) // 2
                               , (A_ScreenHeight - FF_CAWd_Height) // 2
                               , FF_CAWd_Width, FF_CAWd_Height
   SendInput {Click 30, 5, 0}
   While FF4StatusBarText(FF_Handle)
      Sleep 1000
Any help correcting, preventing, or debugging this would be greatly appreciated.

Thanks in advance. :)

Xx7
  • Members
  • 674 posts
  • Last active: Mar 24 2015 10:48 PM
  • Joined: 19 Apr 2011

It is rather inelegant, but he could use ImageSearch to determine when the reload button appears in the browser. In Firefox that means the page is done loading.


Interesting... i never thought of that. :)

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
I recently added Acc_EnumChildren to the Acc Library. Try using this:
FFStatusBarText(hwnd="") { ; tested on FireFox v8

	WinGet, hwnd, id, % hwnd? "ahk_id" hwnd:"ahk_class MozillaWindowClass"

	Win := Acc_ObjectFromWindow(hwnd)

	for PropPage in Acc_EnumChildren(Win)

		if Acc_GetRoleText(PropPage.accRole(0))="property page"

			break

	for StatusBar in Acc_EnumChildren(PropPage)

		if Acc_GetRoleText(StatusBar.accRole(0))="status bar"

			return, StatusBar.accName(0)

}


Honest Abe
  • Members
  • 310 posts
  • Last active: Jan 08 2015 08:56 PM
  • Joined: 07 Jan 2011

It is rather inelegant, but he could use ImageSearch to determine when the reload button appears in the browser. In Firefox that means the page is done loading.


Interesting... i never thought of that. :)


It is a clever idea.
I tried pixelsearch instead, and that worked
(waits for white pixels to replace the red ones).
Although, on some websites, certain content continues to load even after the reload button reappears.

Here are two ways I got it to work:

setTitleMatchmode, 2

+space::
run http://www.youtube.com
winwait, YouTube
while (Px = "")
{
PixelSearch, Px, Py, 938, 82, 955, 95, 0xFFFFFF, 10, Fast
}
msgbox, found
Px := ""
return

!space::
run http://www.youtube.com
winwait, YouTube
loop
{
PixelSearch, Px, Py, 938, 82, 955, 95, 0xFFFFFF, 10, fast
if errorlevel
continue
else
break
}
msgbox, found
return

Win7 (x64)
Look up commands faster by using the AutoHotkey Help File's index.
Start→AllPrograms→AutoHotkey→AutoHotkey Help File