Jump to content

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

Firefox page load wait



  • Please log in to reply
45 replies to this topic
edison
  • Members
  • 29 posts
  • Last active: May 10 2015 11:15 PM
  • Joined: 13 Feb 2013

Hi all,

 

Is there a canonical / reliable way to wait for a recent Firefox (15.0+) to finish loading a page?

 

I found a solution from Jethrow in 2011 using his Acc.ahk, but it tosses an error over 50% of the time. His fix at the time used a now-deprecated  function (Acc_EnumChildren()) and I haven't been able to find any updates.

 

I'm fine with waiting for specific text/content to be on a page, but I can't find a current way of doing that, either.

 

Thanks



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

... now-deprecated  function (Acc_EnumChildren()) and I haven't been able to find any updates.

 

You can use Acc_Children() since it now returns an AHK array.

for each, child in Acc_Children(AccObject)
	if IsObject(child)
		MsgBox Child %each% is a child object.
	else
		MsgBox Child %each% is a child element.


edison
  • Members
  • 29 posts
  • Last active: May 10 2015 11:15 PM
  • Joined: 13 Feb 2013

Thanks for the reply, jethrow!

 

So would this be the proper implementation?

FFwait() {
    WinWaitActive, ahk_class MozillaWindowClass

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

    while, FFStatusBarText()
       sleep, 10
    
    return
}

FFStatusBarText(hwnd="") {
	WinGet, hwnd, id, % hwnd? "ahk_id" hwnd:"ahk_class MozillaWindowClass"
	Win := Acc_ObjectFromWindow(hwnd)
	for PropPage in Acc_Children(Win)
		if Acc_GetRoleText(PropPage.accRole(0)) = "property page"
			break

	for StatusBar in Acc_Children(PropPage)
		if Acc_GetRoleText(StatusBar.accRole(0)) = "status bar"
			return, StatusBar.accName(0)
}

It seems to be working based on the few attempts I've tried.

 

What's the purpose of the MouseMove, 0, 0, 0 in FFwait()?



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

I ran the script for Firefox 12.0 and nothing happened. I see it is a function and is to be called. How do you test this? (At least, I did not get any error messages after including Acc.ahk)



edison
  • Members
  • 29 posts
  • Last active: May 10 2015 11:15 PM
  • Joined: 13 Feb 2013

I ran the script for Firefox 12.0 and nothing happened. I see it is a function and is to be called. How do you test this? (At least, I did not get any error messages after including Acc.ahk)

 

FFwait() simply waits for the page to finish loading. The built-in WinWait allows you to wait for a given window with a specified title, but that doesn't guarantee that the page is entirely loaded. I use them together (which may be redundant):

; Search for "Order Form" link, then select it
SendInput ^fOrder Form{Enter}{Esc}{Enter}
; Wait for the window to have the title "Catalog Order "
WinWait, Catalog Order
; Wait for the page to finish loading
FFwait()
; Select the link after the text "Notes"
SendInput ^fNotes{Enter}{Esc}`t

Note that there are probably much better ways of finding text and links than what I'm doing above. I only started using AHK a few weeks ago and have been using it to automate the data entry procedure I was doing manually. While it works for me, I would suggest using the other methods (whatever they may be). I'll update my code when I figure them out, unless someone more knowledgeable chimes in in the mean time.

 

The point is, use the FFwait() to make sure a page is completely loaded before performing any operations on the page.



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

It would be nice to be able to run a script that ensures that there is a predefined string ("User Name", for example) on the loading or loaded screen before running further lines of code. PS: I also believe the reason for MouseMove, 0, 0, 0 is to move the mouse to the 0,0,0 corner of the screen (a neutral position) to ensure Status Bar Text is not running for other reasons not related to the loading of the page if it is randomly positioned over some link on the page that could trigger unwanted Status Bar Text while the page is loading?



vsub
  • Members
  • 1098 posts
  • Last active: Sep 28 2015 09:48 AM
  • Joined: 10 Nov 2011

Maybe stupid suggestion but since you are using WinWaitActive and since the reload\stop icon is one icon,why not just use PixelGetColor.

For example(I just tried it),I choose as a position x624 y67 which is in the middle of the reload icon(the position of my icon)
While FF is loading some site,the reload icon is replaced by the stop icon and the exact same position becomes different color
A2ACB6 - while loading
FFFFFF - when the site is loaded.
 

WinWaitActive,ahk_class MozillaWindowClass
Loop
{
Sleep,100
PixelGetColor, OutputVar, 624, 67,RGB
If OutputVar = 0xFFFFFF
Break
}
MsgBox,Site Loaded
Return
 


jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

It seems to be working based on the few attempts I've tried.

 

I suspect otherwise. If you put the following code between your for-loops, do you get "Invalid IAccessible Object" ?

Msgbox,, % Acc_Children(PropPage), %ErrorLevel%

If so, it's because Acc_Children returns an AHK Array. A for-loop accesses the key-value pairs, and your code is only working with the keys:

for key in Acc_Children(AccObject) ;// key will be 1,2,etc

 

 

Also, I've personally lost interest in trying to read the Firefox status bar via Acc - see AHK_L / COM confusion.



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

The script as suggested failed on one of my mission-critical apps I tested.

 

I also played with the idea of detection by FindClick() (a fantastic script: http://www.autohotke...ck-2nd-edition/) but if StatusBarText worked it would be the most ideal solution.                                                                                                                                                         



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

Maybe stupid suggestion but since you are using WinWaitActive and since the reload\stop icon is one icon,why not just use PixelGetColor.

For example(I just tried it),I choose as a position x624 y67 which is in the middle of the reload icon(the position of my icon)
While FF is loading some site,the reload icon is replaced by the stop icon and the exact same position becomes different color
A2ACB6 - while loading
FFFFFF - when the site is loaded.
 

WinWaitActive,ahk_class MozillaWindowClass
Loop
{
Sleep,100
PixelGetColor, OutputVar, 624, 67,RGB
If OutputVar = 0xFFFFFF
Break
}
MsgBox,Site Loaded
Return
 

Intriguing approach! But wouldn't reload icon change each time you load a website (I assume using tabs to open new websites)? Also, the icon position changes depending on the display screen.



vsub
  • Members
  • 1098 posts
  • Last active: Sep 28 2015 09:48 AM
  • Joined: 10 Nov 2011
Yes,the icon can be in different positing depending on your display and customizations. I suggested this method because just by looking at edison code,he want to load a page and do things once the page is completely loaded. My method is good enough to allow just that. Can any other method actually allow checking if certain site is completely loaded while you continue browsing other sites in other tabs?

Jstjacques
  • Members
  • 112 posts
  • Last active: May 12 2014 09:43 PM
  • Joined: 10 Jan 2013

Maybe stupid suggestion but since you are using WinWaitActive and since the reload\stop icon is one icon,why not just use PixelGetColor.

For example(I just tried it),I choose as a position x624 y67 which is in the middle of the reload icon(the position of my icon)
While FF is loading some site,the reload icon is replaced by the stop icon and the exact same position becomes different color
A2ACB6 - while loading
FFFFFF - when the site is loaded.
 

WinWaitActive,ahk_class MozillaWindowClass
Loop
{
Sleep,100
PixelGetColor, OutputVar, 624, 67,RGB
If OutputVar = 0xFFFFFF
Break
}
MsgBox,Site Loaded
Return
 

I do this with Google Chrome because they use this swirling circle thing when the page is loading.  It's not 100% but works good enough for what I need it for.


You can get a good look at a steak but shoving your head up a cow's rear end, but wouldn't you rather take the butchers word for it?


edison
  • Members
  • 29 posts
  • Last active: May 10 2015 11:15 PM
  • Joined: 13 Feb 2013

Intriguing approach! But wouldn't reload icon change each time you load a website (I assume using tabs to open new websites)? Also, the icon position changes depending on the display screen.

 

That's exactly what I'm afraid of. Since you can resize the address box / search box, the reload icon's position isn't the same, so this isn't a terribly portable solution.



edison
  • Members
  • 29 posts
  • Last active: May 10 2015 11:15 PM
  • Joined: 13 Feb 2013

I suspect otherwise. If you put the following code between your for-loops, do you get "Invalid IAccessible Object" ?

 

Yes.

 

If so, it's because Acc_Children returns an AHK Array. A for-loop accesses the key-value pairs, and your code is only working with the keys:

 

A-ha! This, then, seems to work:

for key, PropPage in Acc_Children(Win)
...
for key, StatusBar in Acc_Children(PropPage)

 

Also, I've personally lost interest in trying to read the Firefox status bar via Acc - see AHK_L / COM confusion.

 

Sorry for completely missing your reply in my other thread. I should have checked there before posting the new thread, although that was a bit off the original topic.

 

I've added some of my observations and results to that thread, if you care to take another look. I think we may be close.



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

... just thought I'd point out:

PropPage := Acc_ChildrenByRole(Win, "property page")[1]

;// is the same as:

for ,PropPage in Acc_Children(Win) ;// key omitted
	if Acc_GetRoleText(PropPage.accRole(0)) = "property page"
		break

... moreover, Acc_Get() was designed to do what you're trying to do with FFStatusBarText():

Acc_Get("Name", "property_page1.status_bar1", 0, "ahk_class MozillaWindowClass")