11-07-2010, 09:09 AM (This post was last modified: 04-17-2020, 04:07 PM by Gintaras.)
Functions to wait while web browser is busy (loading page).
FUNCTIONS:
FirefoxWait
ChromeWait
2012-08-31. Tested all with current browser versions and fixed broken ChromeWait.
2013-02-27. It seems in Opera 12 accessibility is either removed or broken. Function OperaWait will not work. Now removed.
2015-03-13. ChromeWait now works with Chrome 41.
2015-05-21. ChromeWait now works with Chrome 43.
2020-04-17. Works with Chrome 81 and Firefox 75.
[quote="Gintaras"]Functions to wait while web browser is busy (loading page).
Hi Gintaras, good morning. I'm having problems with an update of Chrome and the routines ChromeWait that was working well. But now it return an error because it not recongnize the end to wait. Put ahead an adaptation of ChromeWait (just changes for spanish, no more that). I'll appreciate your help to determinate what happend. Thanks ins advance and forgive my English.
/
function [$url]
;This is a little adaptation to "ChromeWait" designed and programmed by Gintaras at QM Forum.
;Waits until Chrome is busy (loading page).
;Error if fails, eg if Chrome closed while waiting.
;url - web page address to open.
;;;If empty, just waits while Chrome is busy.
;;;Can include command line, eg "--disable-extensions ''url''".
;To get "busy" state, uses accessible object properties of main toolbar and its Reload button. Also uses window name.
;If your Chrome uses language other than English, the default values may not match.
;Then the function fails (error). Open this function and change the first 4 variables.
;You can discover the values using the 'Find Accessible Object' dialog.
;variables to change. Usually only the last two.
str windowName="Chrome" ;;can be partial
str toolbarName="Barra" ;;can be partial
str buttonName="Cargar " ;;can be partial / In Spanish is Ok In Spanish is Ok this translate. But it's not be comparing ok.
str buttonDescriptionBeginsWith="Cargar página " ;;begins with / In Spanish is Ok this translate.
;____________________________________________
This part is only to demostrate the values of Chrome Windows in differentes instances
State: Finished the download
int w=win("PLOG 23488 en SRSPLOG - Google Chrome" "Chrome_WidgetWin_1")
Acc a1.Find(w "PUSHBUTTON" "Cargar de nuevo" "class=Chrome_WidgetWin_1" 0x1005)
State: While is Downloading
I can't get it like before. But, the button say "Interrumpir la carga de esta página" while is loading
;____________________________________________
spe 100
;run chrome and get window handle
int w1
if(empty(url)) w1=win(windowName "Chrome_WidgetWin_0"); if(!w1) run "chrome" "" "" "" 0x200 3
else run "chrome" url "" "" 0x200 3
Espera hasta que esté visible WV
w1=wait(30 WV win(windowName "Chrome_WidgetWin_0"))
Espera hasta que se crea WC
w1=wait(30 WC win(windowName "Chrome_WidgetWin_0"))
;get toolbar acc
Acc a=acc(toolbarName "TOOLBAR" w1 "" "" 0x1000 0 0 "" 30)
;get Reload button acc
a=acc(buttonName "PUSHBUTTON" a "" "" 16) ;;a.Navigate("c3") would be unreliable
;wait until description changes from "Stop*" to "Reload*"
;In this case, description change from "Interrumpir*" to "Cargar*". Something in the kind of buttoms changed in Chrome.
int n
rep
0.1
_s=a.Description;; out _s
Here is, maybe, the problem..... The active buttom
if(_s.begi(buttonDescriptionBeginsWith)) n+1; if(n=10) break
else n=0
In my ChromeWait version change Chrome_WidgetWin_0 to Chrome_WidgetWin_1. Or replace with the new version, I uploaded today.
Then change the 3 variables if need for Spanish. For English they didn't change in new Chrome.
I didn't test your ChromeWait version.
Hi again, I find the problem. Chrome changed the name of button to control.
Before it was: ; get Reload button acc
a=acc(buttonName "PUSHBUTTON" a "" "" 16)
Now, it work ok: ; get Reload button acc
a=acc(buttonName "BUTTONDROPDOWN" a "" "" 16)
To Spanish, the variable setting is: ; variables to change. Usually only the last two.
str toolbarName="Chrome" ;;can be partial
str buttonName="Cargar" ;;can be partial
str buttonDescriptionBeginsWith="Cargar" ;;begins with
I was surprised this morning to discover that Google Chrome reload button acc.Description is now empty. I am wondering about the way one could then detect the busy state. One idea that I have at this moment is to use scan to detect the button's image (stop or reload image). Any advice will be most welcome.
Thanks in advance
PS : I attach herewith a version of my new wait for chrome routine, which it works satisfactorily. I will be pleased to answer any inquiries.
str si.getmacro(getopt(itemid)1) str caller.getmacro(getopt(itemid 1)1);err caller=si if ideb;min0;errout"<>%s : <open ''%s /%i''>%s</open> - Called by : %s"NowT si _error.place si caller
int w=win("New Tab - Google Chrome""Chrome_WidgetWin_1")
;---> Comment 21-05-2015 10:25:43 : Changes in GC ;a1.Description is now Empty !
;Waits while Chrome is busy (loading page). ;Returns window handle. ;Error if fails, eg if Chrome closed while waiting. ;Tested with Google Chrome 7.0 and 21.0. May not work with other versions.
;url - web page address to open. ;;;If empty, just waits while Chrome is busy. ;;;Can include command line, eg "--disable-extensions ''url''".
;May not wait if this function opens new window when a window already exists. ;Does not work if toolbar or its Reload button does not exist.
;To get "busy" state, uses accessible object properties of main toolbar and its Reload button. ;If your Chrome uses language other than English, the default values may not match. Then the function fails (error). Open this function and change variables. You can discover the values using the 'Find Accessible Object' dialog.
;variables to change. Usually only the last two. ;str toolbarName="Chrome" ;;can be partial str buttonName="Reload";;can be partial str buttonDescriptionBeginsWith="Reload";;begins with
;____________________________________________
int w1=WB_Open("chrome" url "Chrome""Chrome_WidgetWin_*"0x804)
;---> Comment 13-03-2015 11:15:05 : toolbarName changed from "Chrome" to "main" str toolbarName="main";;can be partial
; ;get toolbar acc Acc a=acc(toolbarName "TOOLBAR" w1 """"0x101000""30) ;get Reload button acc err ,_s=_error.description ,out"<>%s : <open ''%s /%i''>%s</open> - %s"NowT si _error.place si _s ,mac"Warning_QM" si ,end
a=acc(buttonName "PUSHBUTTON" a """"16) err ,_s=_error.description ,out"<>%s : <open ''%s /%i''>%s</open> - %s"NowT si _error.place si _s ,mac"Warning_QM" si ,end
int x y cx cy
a.Location(x y cx cy) ;out F"{x} {y} {x+cx} {y+cy} "
str scr=F"C:\Documents and Settings\S.E.Simopoulos\My QM\bmp\GC_Reload_{uSN}.bmp" if!scr.FileExistS ,_s=F"Scan File does not exist : {scr} - Caller : <open>{caller}</open>" ,min0;errout"<>%s : <open ''%s /%i''>%s</open> - %s"NowT si _error.place si _s ,mac"Warning_QM" si 0 ,end
RECT r
int n
mac"ChromeWait_TrayInd"
opt waitmsg -1 int waitmax=60 int wt(waitmax*1000) t1(GetTickCount) rep ,0.1 ,r.left=x; r.top=y; r.right=x+cx; r.bottom=y+cy ,int i=scan(scr 0 r 010) ,if i ,,n+1 ,,;_s.format("%i" n) ,,;min 0; err out "<>%s : <open ''%s /%i''>%s</open> - %s" NowT si _error.place si _s ,,if(n=10)break ,else ,,n=0
,if(wt>0andGetTickCount-t1>=wt) ,,_s=F"Wait Timeout - Caller : <open>{caller}</open>" ,,min0;errout"<>%s : <open ''%s /%i''>%s</open> - %s"NowT si _error.place si _s ,,mac"Warning_QM" si 0 ,,shutdown-60"ChromeWait_TrayInd" ,,end
shutdown-60"ChromeWait_TrayInd" ret w1 err+endES_FAILED
;info: Chrome 7.0 toolbar buttons are not customizable.
;Waits while Chrome is busy (loading page). ;Returns window handle. ;Error if fails, eg if Chrome closed while waiting. ;Tested with Google Chrome 43.0. May not work with other versions.
;url - web page address to open. ;;;If empty, just waits while Chrome is busy. ;;;Can include command line, eg "--disable-extensions ''url''".
;May not wait if this function opens new window when a window already exists. ;Does not work if toolbar or its Reload button does not exist.
;To get "busy" state, uses accessible object properties of main toolbar and its Reload button. ;If your Chrome uses language other than English, the default values may not match. Then the function fails (error). Open this function and change variables. You can discover the values using the 'Find Accessible Object' dialog.
;Waits for pixel color 0x505050 in Reload button, at x=0.5 y=0.3 of the button Acc object rectangle. May need to change the color or coordinate. ;Activates Chrome window, because the Reload button must be visible on screen.
;variables to change str toolbarName="Chrome|^main$";;regexp. In Chrome 39 it contains "Chrome"; in Chrome 41-43 it is "main". str buttonName="Reload";;can be partial
;____________________________________________
int w=WB_Open("chrome" url "Chrome""Chrome_WidgetWin_*"0x804)
;get toolbar acc Acc a=acc(toolbarName "TOOLBAR" w """"0x101200""30) ;get Reload button acc
a=acc(buttonName "PUSHBUTTON" a """"16)
;get a 1-pixel rectangle in the circle-arrow ("Reload" image) RECT r rr int x y wid hei
a.Location(x y wid hei)
r.left=x+(wid/2); r.top=y+(hei*0.3);;may need to change. It must be a pixel from "Reload" image (circle-arrow), not from "Stop" image (X) and not from background. DpiScreenToClient w +&r
r.right=r.left+1; r.bottom=r.top+1 ;out "%X" pixel(r.left r.top w 1) ;;show the color ;mou r.left r.top w 1; ret ;;show the place
;wait for color rep8;;retry because button image can change several times ,0.1 ,act w ,rr=r ,wait0 S "color:0x505050" w rr 1632;;may need to change color here. The 32 is allowed color difference.
My simple contribution to users of Chrome in Spanish is this little adjust in a part of your code:
;variables to change
str toolbarName="Chrome|principal$" ;;regexp. In Chrome 39 it contains "Chrome"; in Chrome 41-43 it is "principal".
str buttonName="Cargar" ;;can be partial
I tested the new function in Spanish and work in excelent way, like ever.
PD: I don't know why de Chrome team's is working hard just to give us this kind of problems. :roll: