A simple UsePage replaces complex Pause blocks

Scripts for common tasks

A simple UsePage replaces complex Pause blocks

Postby Mike on Mon Dec 07, 2009 11:50 am

We have noticed that many programmers use a Pause block to detect that a new web page (or a new window) is there.
The first code shows how it is done with a Pause, the second code shows how it can be done with just a UsePage for a much simpler script.
Code: Select all
'If the Pause fails, an error proc is called.
Sub proc_error()
'report an error in a log file
comment("Page Features not seen")
'Kill Internet Explorer, so the desktop is clean for next execution.
KillApp("IEXPLORE.EXE",1)
End
EndSub

StartBrowser("IE", "www.wintask.com")

UsePage("WinTask - Automation software and Task Scheduler. Macro software with Macro Recorder")
   ClickHTMLElement("A[INNERTEXT= 'WinTask Features']")

'Wait a maximum of 60 secs for the page WinTask Features to be loaded, the pause checks that the sentence Unlimited length of is there
'The same structure applies for a Pause OCR Text.
   Pause 10 secs until
      Text("BlaUnlimited length of")
      'to have a failure, use for example        Text("BlaUnlimited length of")
      InWindowAnyinstance("IEXPLORE.EXE|Internet Explorer_Server|WinTask - Features - Windows Internet Explorer|1")
   PauseFalse
      ' call the error proc if the pause fails. This call avoids a goto line which MUST be avoided for a good programming.
      proc_error
   EndPause
'If the pause succeeds, just go on
CloseBrowser()




Now with a UsePage:
Code: Select all
Sub proc_error()
'report an error in a log file
comment("Page Features not seen")
'Kill Internet Explorer, so the desktop is clean for next execution.
KillApp("IEXPLORE.EXE",1)
End
EndSub

OnAction Error
   DoSub proc_error
EndAction

StartBrowser("IE", "www.wintask.com")

UsePage("WinTask - Automation software and Task Scheduler. Macro software with Macro Recorder")
   ClickHTMLElement("A[INNERTEXT= 'WinTask Features']")

'Wait a maximum of 60 secs before reporting an error, so change the default value of #ActionTimout to 60
#ActionTimeout=60

'As all the pages start with WinTask, force an exact recognition of the page title
#UsePageExact=1

UsePage("WinTask - Features")
'if the UsePage succeeds, the script goes on, if the UsePage fails, the page is not there, OnAction Error triggers.
'To test a failure, use for example UsePage("WinTask - TFeatures")

CloseBrowser()

'The same technique applies with a UseWindow. To force an exact recognition of the window name, use #UseExact=1
Mike
 
Posts: 5
Joined: Fri Dec 04, 2009 3:24 pm

Return to Sample Scripts and Tips

Who is online

Users browsing this forum: No registered users and 2 guests

cron