WinTask Web Book

Transcription

WinTask Web Book
WINTASK
Develop efficient and reliable
Web automation scripts
Version 5.1
AUTOMATION FOR WINDOWS (Windows 7/8, 2003, 2008 and 2012 Server)
Published by:
TaskWare
25 rue de Naples
75008 PARIS France
© Copyright 1997-2014 TaskWare
October 2014
WinTask is a trademark of TaskWare.
-2-
CONTENTS
Introduction ........................................................... 6
Why WinTask? ........................................................................................... 6
WinTask Components ................................................................................. 6
TASKEDIT ................................................................................................. 6
TASKCOMP ................................................................................................ 6
TASKEXEC ................................................................................................. 7
SPY .......................................................................................................... 7
TASKWIZ .................................................................................................. 7
DIALOG BOX EDITOR ................................................................................. 7
Recording Mode ...................................................... 9
Exercise 1 ................................................................................................. 9
Capture/Replay Tool Myths ........................................................................ 10
Exercise 2 ............................................................................................... 10
A Simple Automation Script ....................................................................... 11
WinTask Editor ..................................................... 13
Exercise 3 ............................................................................................... 13
Terminating a Script ................................................................................. 14
Synchronization .................................................... 15
Synchronization when all the pages of the website has the same title ............. 15
Exercise 4 ............................................................................................... 15
Manual Synchronization ............................................................................ 16
Exercise 5 : Text Synchronization ............................................................... 18
Exercise 6 : Synchronization on OCR Text ................................................... 20
Exercise 7 : Window Synchronization .......................................................... 26
Synchronization waiting for a PDF file to be fully displayed ............................ 30
Exercise 8 ............................................................................................... 30
WinTask Scripting Language .................................. 33
Language Functions .................................................................................. 33
Variables ................................................................................................. 35
System Variables ..................................................................................... 35
Integers .................................................................................................. 35
Strings .................................................................................................... 36
Reals ...................................................................................................... 36
Arrays .................................................................................................... 36
Operators ................................................................................................ 36
Web Page Management Functions .......................... 39
#IgnoreErrors.......................................................................................... 39
#ActionTimeout ....................................................................................... 39
#UsePageExact ........................................................................................ 40
Exercise 9 : Using different Web functions and managing variables................. 41
Iteration .............................................................. 45
Iteration ................................................................................................. 45
Exercise 10 : Iteration for clicking the ith page ............................................ 45
File Functions ....................................................... 47
Exist() .................................................................................................... 47
-3-
Kill() ....................................................................................................... 47
Read() et Write()...................................................................................... 48
ReadExcel et WriteExcel ............................................................................ 48
Web Data Capture Functions .................................. 51
Exercise 11 : Web data extraction .............................................................. 51
Automatic Web Form Filling ................................... 59
Exercise 12 : Typing constants in a Web form .............................................. 59
Exercise 13 : Typing data read in an Excel file in a Web form ......................... 60
Other functions for Web forms automation................................................... 62
Subroutines and Functions ..................................... 65
Sub...EndSub ........................................................................................... 65
Converting a Script into a Subroutine .......................................................... 66
Exercise 14 : Converting a Script into a Sub ................................................ 66
Function...EndFunction .............................................................................. 67
Data Capture Script on a "real" Web site ................ 71
Exercise 15 : Full Data Capture Script ......................................................... 71
Debugging ............................................................ 83
Compilation errors .................................................................................... 83
Execution errors ....................................................................................... 83
Trace using MsgBox or MsgFrame ............................................................... 83
Exercise 16 : Trace script execution using MsgBox or MsgFrame .................... 83
Log File ................................................................................................... 84
Exercise 17 : Trace execution using a log file ............................................... 84
Timeout error message on a page loading ................................................... 85
ClickHTMLElement does not return an error but does not click ........................ 86
Navigate, a workaround ............................................................................ 86
Incorrect Form Filling ................................................................................ 87
HTML object not found .............................................................................. 87
A Table capture does not return the expected data ....................................... 88
Exercise 18 : CONTENT keyword change for a correct capture ........................ 88
Internet Explorer Menu Option not selected ................................................. 95
Option in a menu of a Web page not selected............................................... 95
Context menu selection does not replay ...................................................... 96
Low level Recording mode when nothing works ............................................ 96
Slow execution ......................................................................................... 98
Capture Wizard cannot capture the desired data ........................................... 98
Conclusion ............................................................ 99
APPENDIX A ................................................................. 101
WinTask Toolbar ..................................................................................... 101
APPENDIX B.................................................................. 103
WinTask Floating Toolbar ......................................................................... 103
APPENDIX C .................................................................. 105
Exercises Solutions ................................................................................. 105
Exercise 4, Scriptweb04.src .................................................................... 105
Exercise 5, Scriptweb05.src .................................................................... 106
Exercise 9, Scriptweb09a.src................................................................... 110
Exercise 9, Scriptweb09b.src .................................................................. 111
Exercise 9, Scriptweb09c.src ................................................................... 112
Exercise 9, Scriptweb09d.src .................................................................. 113
Exercise 10, Scriptweb10a.src ................................................................. 114
-4-
Exercice
Exercise
Exercise
Exercise
Exercise
Exercise
Exercise
Exercise
Exercise
10,
11,
12,
13,
14,
15,
16,
17,
18,
Scriptweb10b.src ................................................................
Scriptweb11.src ..................................................................
Scriptweb12.src ..................................................................
Scriptweb13a.src ................................................................
Scriptweb14a.src ................................................................
Scriptweb15.src ..................................................................
Scriptweb16.src ..................................................................
Scriptweb17a.src ................................................................
Scriptweb18.src ..................................................................
115
116
117
118
120
121
123
124
126
GLOSSARY ....................................................................127
Index ...........................................................................129
-5-
I n t ro d u c t i o n
This manual has been written to give WinTask users a comprehensive resource to
create efficient and reliable Web automation scripts. The manual covers the WinTask
tool-set, the WinTask script language and the WinTask Application Programming
Interface (API).
The manual also provides exercises that help to illustrate the capabilities of WinTask
and how to avoid common pitfalls. The exercises in this manual use simple demo Web
pages on www.wintask.com/demos as automation targets. Once the reader masters
the exercises, it should be an easy transition to apply that knowledge to the Web sites
that they wish to automate. This manual does not cover pure Windows applications
automation – this part is covered in another manual that can be downloaded from
www.wintask.com/manuals.php.
Why WinTask?
WinTask is a complete automation tool for Windows and Web. It can automate any
Windows application or Web page.
WinTask is more than just another macro
recorder. The automation script can be extended to include standard programming
paradigms well beyond a simple repetition of steps. It provides too Capture tools for
extracting data from Web pages, and it includes OCR techniques for even capturing
text embedded in an image displayed on a Web page. To execute your automation
scripts unattended, you can schedule them using WinTask x64 Scheduler (available
only under the 64 bits versions of Windows).
WinTask Components
WinTask is composed of several components. Each of the components is fully
explained later in the manual. Accompanying exercises illustrate how to use each
component.
TASKEDIT
This is the WinTask Integrated Development Editor (IDE) Windows application. With
the Editor, the user can record keyboard entries and mouse actions to generate an
automation script file. The WinTask Script Language syntax is similar to Microsoft
Visual Basic and provides a powerful set of library functions. Script files can be
modified through the Editor, compiled, and executed to automate any application.
WinTask Script Language files are stored in ASCII format (or Unicode) and have a
.SRC extension. The Editor is a multi-pane window, main one showing the script code,
the one on the right displays all the functions available in the language (the Language
window), the one at the bottom displays results when the script is executed (the
Output window). At any time, help on a function can be accessed by double-clicking its
name in the Language window.
TASKCOMP
This WinTask component is a command line program that compiles WinTask Script
Language files into a file that can be interpreted by the Executor. It can be invoked
too through the Editor. The compiler flags any violations of the WinTask Script
-6-
Language syntax in the script file and reports them to the user (Compilation errors are
listed in the Output window). The compiler generates two files with .ROB and .LST
extensions for each script file compiled. The executable script files are created with
the .ROB extension and are binary in nature. The .LST files are where the compiler
logs errors and warnings along with detailed program statistics. This file is an ASCII
file.
TASKEXEC
The WinTask Executor executable interprets compiled WinTask Script Language files
and generates the keystrokes and mouse actions that automate a Web or Windows
application. Compiled WinTask Script Language files have a .ROB extension. A
separate instance of the Executor executes each compiled script file.
SPY
The WinTask Spy component is used to peer into the internal data structures of Web
pages to extract the unique identifiers of each HTML object displayed on the Web
page. This identifier is called an HTML descriptor and is used by many WinTask
functions in order to access the different objects on the page in an object-oriented
way instead of just clicking at mouse coordinates.
TASKWIZ
The WinTask Editor provides a recording mode that provides access to a set of
Synchronization Wizards and to a Capture wizard. This last one allows to capture data
from Web pages and store them into Excel, or into an array for a further use. The
Synchronization Wizards are explained in the chapter titled Synchronization.
DIALOG BOX EDITOR
The WinTask Editor provides a dialog box editor that allows the user to develop dialog
boxes for display during the execution of automation scripts. Dialog boxes provide the
ability to collect information during automation script execution to customize the
actions of the script from run to run. Development and invocation of dialog boxes is
explained in the chapter titled Dialog Boxes.
-7-
-8-
Recording Mode
The quickest way to start automating a Web site or a data extraction is to record your
keystrokes and mouse actions into an automation script. The WinTask Editor has a
recording mode that performs this function. The automation script can then be saved
and replayed at a later date.
Exercise 1
This exercise demonstrates how to record a user session using Web pages as the
application to be automated. The Web pages are under www.wintask.com/demos.
1.
Launch the WinTask Editor by clicking the Windows Start button, then click
All Programs, select WinTask in the list of Programs and double click
WinTask. If Your First Script Wizard screen comes up, click Cancel button.
2.
When the WinTask Editor window comes up, click the Record button
on the WinTask Toolbar to start Recording Mode.
3.
When the Starting Recording Mode dialog box appears, check Mozilla
Firefox (or Internet Explorer checkbox, or Google Chrome checkbox if
you prefer to use Internet Explorer ou Google Chrome) and click the OK
button.
4.
The Launching Mozilla Firefox dialog box (or the Launching Internet
Explorer dialog box or the Launching Google Chrome dialog box) will
appear. Enter www.wintask.com/demos into the Web address field and
click the OK button.
5.
The Web page titled WinTask Demonstration Pages will open, and WinTask
will transform itself into a floating toolbar titled WinTask Toolbar. There will
also be a flashing icon
added to the system tray that indicates
that Recording Mode is active. Click the link Page 2 in the body part of the
page.
6.
The Web page titled Page 2 is now displayed. Type WinTask Test in the
Your Company: field and click the link here in the and click here to come
back to Home page sentence to come back to the first Web page.
7.
Click the Stop Recording button
Recording Mode.
8.
The WinTask Editor window is restored to its normal size and the recorded
automation script is displayed in the text area.
-9-
on the WinTask Floating Toolbar to stop
9.
Close the Firefox window (or the Internet Explorer window or the Google
Chrome window) by clicking the Close icon
at the top right of the
Internet Explorer or the Firefox window or the Chrome window.
10.
Click the Play button
on the WinTask toolbar to run the previously
recorded script. You are prompted for saving the file, give the name
scriptweb01, and click Save button, you see all your actions replayed. Close
the browser window.
11.
From the WinTask Editor, select menu item File/Exit.
Capture/Replay Tool Myths
At first glance, it may appear that any Capture/Replay tool is sufficient to automate a
task. It soon becomes apparent that unless the tool is flexible enough to handle a
dynamic PC environment, the replay aspects will not meet expectations.
Exercise 2
In this exercise WinTask will be used in a purely Capture/Replay style. It will be
shown that generated automation scripts may not always execute successfully !
This exercise uses Mozilla Firefox.
1.
Launch the WinTask Editor. If Your First Script Wizard screen comes up, click
Cancel button. The title bar should display WinTask – [Untitled1]. If not
select menu item File/New or click the New icon in the Editor toolbar.
2.
Click the Record button
Mode.
3.
When the Starting Recording Mode dialog box appears, check Mozilla
Firefox checkbox and click the OK button.
4.
The Launching Mozilla Firefox dialog box will appear.
Enter
www.wintask.com/demos into the Web address field and click the OK
button.
5.
The Web page titled WinTask Demonstration Pages will open, and WinTask
will transform itself into a floating toolbar titled WinTask Toolbar. Click the
link File in the body part of the page.
6.
The Open test.test window is now displayed. Click the OK button.
7.
In the next window Enter name to file to save to, leave the file name
test.test and click the Save button.
on the WinTask Toolbar to start Recording
- 10 -
8.
Click the Stop Recording button
Recording Mode.
on the WinTask Floating Toolbar to stop
9.
The WinTask Editor window is restored to its normal size and the recorded
automation script is displayed in the text area.
10.
Close the Firefox window by clicking the Close icon
the Firefox window.
at the top right of
11.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. WinTask will now compile the script before running it. You
will be prompted to save the script. Enter the name scriptweb02 when the
Save As dialog is displayed. The Compilation results are displayed in the
Output window of the Editor and the compiled script starts its execution.
Please refrain from moving the mouse or entering any keystrokes as the script
is executed.
12.
As you watch the WinTask Executor execute the compiled script you will see a
repetition of Steps 4 through 7. You will notice that the script doesn’t save
the file and remains open on the Confirm Save As dialog box.
13.
Click the Yes button on the Confirm Save As dialog box and close Mozilla
Firefox.
14.
Questions for Discussion: What are the causes of the script’s failure to run to
completion?
How might the script be modified to allow it to run to
completion?
When your actions were recorded in the script, file test.test did not exist. When the
script is replayed, the Save dialog detects that a file by the same name exists and
prompts the WinTask Executor to confirm that the file is to be overwritten. The script
has not been created to handle this situation and so does not save the file.
Without manual modifications to an automation script, the script will only complete
successfully if the PC environment is IN THE SAME STATE as at the time when the
script was recorded. Using Exercise 2 as an example, file test.test must be deleted
prior to the execution of the compiled scriptweb02.src. This can be accomplished by
manually deleting the file, defeating the purpose of an automation script, or modifying
the script to delete the file if it exists.
A Simple Automation Script
So far we have ignored the contents of the automation script file created during
Exercise 1.
The following section examines the individual lines stored in
scriptweb01.src. The lines from the script file are listed in Italic followed by a short
explanation of what action each line performs. Based upon your actions during the
- 11 -
recording session, your version of the file may contain additional lines not documented
here.
The user can view the script file in the WinTask Editor. Placing the cursor on the
name of the function call and pressing the F1 key will bring up the WinTask Help
System for the function. Descriptions of many WinTask Application Programming
Interface functions can be found throughout this manual.
StartBrowser("IE",
"www.wintask.com/demos")
or
StartBrowser("FF",
"www.wintask.com/demos") or StartBrowser("CH", "www.wintask.com/demos")
StartBrowser starts IE (Internet Explorer), or starts FF (Firefox), or starts CH
(Chrome) as a new process. The second parameter tells which url has to be loaded
when Internet Explorer (or Firefox or Chrome) starts. If you use a x64 version of
Windows, note that the browser launched by this StartBrowser function is the x32
version of Internet Explorer (the one under C:\Program Files (x86)\Internet
Explorer directory).
UsePage("WinTask Demonstration Pages")
UsePage defines the target Web page for all WinTask generated keystrokes and
mouse actions. The function will wait for the specified page to be fully loaded up to
a timeout value before displaying an error message. The default timeout value is
30 seconds. This line will wait for the page titled WinTask Demonstration Pages to
fully load and display. Focus is placed on the Web page.
ClickHTMLElement("A[INNERTEXT= ' Page 2']")
ClickHTMLElement clicks the link which is specified in the parameter of the
function. The HTML object to click on is described by its HTML descriptor:
Recording mode generates automatically the descriptor, which is usually based on
the text displayed for the link. ALWAYS use Recording mode to generate the
correct HTML descriptor.
UsePage("Page 2")
This UsePage function call tells that now the target for keystrokes and mouse
actions is the Web page titled "Page 2".
WriteHTML("INPUT TEXT[NAME= 'company']", "WinTask Test")
WriteHTML writes a text in a Web form field. The first parameter of the function
specified the name of the field where to write, the second parameter is a string of
characters, the text to write in the field.
ClickHTMLElement("A[INNERTEXT= 'here']")
ClickHTMLElement clicks the link which is specified in the parameter of the
function. The HTML descriptor used for this link is again based on the text of the
link "here".
- 12 -
Wi n Ta s k E d i t o r
The WinTask Editor provides full IDE capabilities to support the development of
automation scripts. The user can record, edit, compile and execute scripts through
the user interface of the WinTask Editor. Context sensitive Help on the WinTask Script
Language is also available when editing a script: put the cursor under a function name
within the script and press F1, the help on that function is displayed. The list of all
available functions is displayed in a pane on the right of the main Editor window (press
F4 if you don't see it), it is called the Language window. The bottom pane, called
Output window, returns the Compilation error if any, and can display results when
debugging a script. If multiple scripts are opened, a click on the Tab of the desired
script puts the focus on it.
Exercise 3
This exercise demonstrates integration of the WinTask Editor with the WinTask
Compiler, the WinTask Executor and the WinTask context sensitive Help.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. If WinTask opens a previously saved script (Ex. scriptweb02.src),
close the window by selecting menu item File/Close and click the Open
button on the WinTask Toolbar or select menu item File/Open. Open
scriptweb01.src.
2.
From WinTask, select menu item File/Save As.
Enter the name
scriptweb03.src when the Save As dialog is displayed. This step prepares
for this exercise by changing the script name and keeps the scriptweb01.src
available as a reference.
3.
In the Editor window, place the cursor at the end of the line which contains
the WriteHTML function and press Enter key.
4.
Type the following on the blank line : MsgBox(Hello Tester") (Type exactly
as listed).
5.
Place the cursor at the end of the last line of the script and press Enter key.
Type the following on the blank line : MsgBox("Tester: end of script").
6.
Click the Play button
7.
The WinTask Compiler will detect the error and writes several error messages
to the Output window of the Editor. Review the errors and double click the
first error. The cursor will be moved to the point of the error in the Edit
window containing scriptweb03.src. Note that the WinTask Status Bar
to replay the script.
- 13 -
displays the line and column numbers of the cursor location at the bottomright of the window.
8.
At the very beginning of the line which returns an error, insert the character '
(single quote). The line is now commented and its color becomes green. Note
too that the functions names are colored in blue.
9.
Now place the cursor at the beginning of the first line in the script. Select
menu item Edit/Replace. Use the Replace dialog box to replace the word
Tester by the word Developer everywhere in the script.
10.
Click the Play button
to replay the script. Script execution goes to its
end and a dialog box Developer: end of the script is displayed. Click OK
button.
11.
Come back to the WinTask Editor window and delete the character ' at the line
where you have inserted it. Place the cursor under the word MsgBox, and
press F1 to invoke the context sensitive help for MsgBox.
12.
Review the help page on MsgBox, correct the syntax of the MsgBox line in
the script to avoid the compilation error. Note the text color change when the
syntax becomes correct. Close the help window.
13.
Click the Play button to replay the script. Click the OK button when the first
dialog box appears. Click again the OK button when Developer: end of the
script is displayed.
14.
Close manually all the Internet Explorer (or Firefox or Chrome) windows.
Terminating a Script
There are times when you may want to terminate an actively running automation
script. This can be accomplished by simultaneously pressing the Ctrl+Shift+Pause
keys. The script stops when the current line under execution has finished processing.
- 14 -
S y n c h ro n i z a t i o n
When the WinTask Executor replays a Web automation script, it needs to wait for the
page to be fully loaded before it can execute the next action. In the previous
exercises you had to wait for the page titled Page 2 fully loaded before you could enter
text into the form field. Task automation cannot be realized without synchronization
between actions.
WinTask accomplishes synchronization through functions that automatically wait for
Web objects fully loaded and ready to receive actions. The UsePage function provides
automatic synchronization by waiting for a Web page to load and become ready when
the next action must be done in that page. WinTask will report an error after reaching
an internal timeout value (default timeout is 30 seconds) if the page is unavailable.
The ClickHTMLElement, WriteHTML, … functions wait too until the specified HTML
object is there and ready before processing the action (click on a link, typing in a form
field,…).
At times, the automatic synchronization through the UsePage function is not enough,
and the user must manually add synchronization to the automation script. This
chapter gives examples on sample Web pages under www.wintask.com/demos, where
a manual synchronization must be added.
Appendix C contains the solution for these exercises.
Synchronization when all the pages of the website has the same
title
Exercise 4
This exercise demonstrates how to add a manual synchronization when all the pages
of the website have the same title. Appendix C contains the solution for this exercise.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. If WinTask opens a previously saved script (Ex. scriptweb03.src),
close the window by selecting menu item File/Close and click the New
button on the WinTask Toolbar or select menu item File/New.
2.
Click the Record button
3.
When the Starting Recording Mode dialog box appears, check Mozilla
Firefox checkbox (or Internet Exploer checkbox if you prefer to use Firefox,
to start Recording Mode.
- 15 -
or Google Chrome checkbox if you prefer to use Chrome) and click the OK
button.
4.
The Launching Mozilla Firefox dialog box (or the Launching Internet
Explorer dialog box, or the Google Chrome dialog box) will appear. Enter
www.wintask.com/demos/identicalpage1.htm into the Web address
field and click the OK button.
5.
The Web page titled Page Title will open, and WinTask will transform itself
into a floating toolbar titled WinTask Toolbar. Click the link here in the
Click here to go to the next page with the same title sentence.
6.
Click the link previous page in the Come back to the previous page
sentence.
7.
The previous page with the same title loads, type My name in the Your
Name field and click in the Your Company field without typing anything.
8.
Close the browser window by clicking the Close icon
of the browser window.
9.
Click the Stop Recording button
Recording Mode.
at the top right
on the WinTask Floating Toolbar to stop
10.
The WinTask Editor window is restored to its normal size and the recorded
automation script is displayed in the text area.
11.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. WinTask will now compile the script before running it. You
will be prompted to save the script. Enter the name scriptweb04 when the
Save As dialog is displayed. The Compilation results are displayed in the
Output window of the Editor and the compiled script starts its execution.
12.
The script as generated by Recording mode has little chance to run smoothly
because the UsePage functions are not generated automatically if the next
page has the same title as the previous one.
13.
Add manually the UsePage lines at the correct places to ensure a correct
synchronization.
14.
Click the Play button
on the WinTask Toolbar to replay again the
actions listed in the script. It should now replay correctly.
Manual Synchronization
WinTask includes manual synchronization methods which can be added during a
Recording session if the UsePage function or ClickHTMLElement, WriteHTML, …
functions are not enough to ensure a smooth synchronization. A wizard is available to
- 16 -
generate and insert automation script snippets to handle each synchronization
method. When invoking a synchronization wizard from the WinTask Editor, the
generated script is inserted into the active script window at the current cursor
position.
If invoked during Recording Mode, the synchronization lines are
automatically included at that point in the recording process.
The WinTask Help System provides additional details on how to use each wizard. See
Appendix A for screen shots of the WinTask Toolbar buttons that invoke each wizard.
See Appendix B for screen shots of the WinTask Floating Toolbar and the buttons that
invoke each synchronization wizard during Recording Mode.

Text Synchronization
This synchronization waits until a pre-defined text string appears somewhere in a
window. Such a synchronization is not needed for waiting that a Web page has
finished to load because the ClickHTMLElement, WriteHTML, …. Functions wait until
the specified object is there. The most common use is to wait until a text in a
mainframe emulation window is displayed before typing. On Web pages, the
manual synchronization is not needed.

Synchronization on OCR Text
This synchronization waits until a pre-defined text string displayed within an
image. This synchronization method is used in the same circumstances than
Synchronization on Text and if the displayed text is not seen by WinTask. The OCR
engine takes some time to transform the captured image in a text, it can take
from several tenth of seconds till 3 seconds. So use this method only if the
synchronization cannot be done through a UsePage, or ClickHTMLElement,
WriteHTML, … . The OCR Text Synchronization wizard can be accessed through the
WinTask Editor Insert/Synchronization/On OCR Text menu item.

Bitmap Synchronization
This synchronization waits until a pre-defined image appears somewhere in the
Internet Explorer window. One area where this type of synchronization may be
useful is waiting for a Flash web page to load (if you need to click icons without
any text on a Flash page, the OCR text synchronization cannot apply and so only a
bitmap synchronization is possible). The bitmap generated by the synchronization
wizard relies on the screen resolution, so if the script runs on another PC with
another screen resolution, it will fail, so use Bitmap Synchronization only when no
other method is possible. The Image Synchronization wizard can be accessed
through the WinTask Editor Insert/Synchronization/On Image menu item.

Window Synchronization
This synchronization waits until a new window is displayed or becomes active or
disappears. A user may use this type of synchronization to wait until the
download of a file from a web site has finished. The Window Synchronization
wizard can be accessed through the WinTask Editor Insert/Synchronization/On
Window menu item.
- 17 -

Time Synchronization
It is the most simple synchronization : it waits until a specified amount of time has
expired. The time interval can be set to hundredths of a second (tick unit),
seconds, minutes, hours, days. Time synchronization has to be used for example
on Ajax forms where the content of a field is not the same depending what the
user has selected in the previous field. A small time interval must then be added
to be sure that the field has enough time to be populated by the values depending
on the previous selection in the form. The Time Delay Synchronization wizard can
be accessed through the WinTask Editor Insert/Synchronization/On Time
Delay menu item.

Date/Hour Synchronization
This synchronization waits until a specified date and time. This Synchronization
method is rarely used as it is more efficient to use WinTask Scheduler to run a
script every day at the same time for example. The Date/Hour Synchronization
wizard can be accessed through the WinTask Editor Insert/Synchronization/On
Date/Hour menu item.

Keyboard, Menu, Mouse Wait
They are not used in a Web automation script.
Exercise 5 : Text Synchronization
This exercise demonstrates how to invoke and use the Text Synchronization wizard
while recording an automation script, to wait until a text is displayed. It uses notepad
as this application is available in any Windows version. Appendix C contains the
solution for this exercise.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. If WinTask opens a previously saved script (Ex. scriptweb04.src),
close the window by selecting menu item File/Close and click the New
button on the WinTask Toolbar or select menu item File/New.
2.
Click the Record button
3.
When the Starting Recording Mode dialog box appears, check An
application checkbox and click the OK button.
4.
The Launching a program dialog box will appear. Enter notepad into the
Program field and click the OK button.
5.
The notepad window opens, type Hello WinTask and press Enter twice.
Then type The weather is warm today.
6.
Invoke the Text Synchronization wizard by clicking the Text Synchronization
button
7.
to start Recording Mode.
on the WinTask Floating Toolbar. Recording mode is suspended.
Click the Capture button on the Text Synchronization wizard. The wizard will
be
hidden
and
the
cursor
will
change
to
a
crosshair.
- 18 -
8.
Use a drag box to capture the text is warm in the notepad window. Uncheck
Only in this area.
9.
Click the Insert and Resume button.
10.
Close the notepad window. Do not save the notepad document.
11.
Click the Stop Recording button on the WinTask Floating Toolbar to stop
Recording Mode.
The Text Synchronization wizard inserted the following lines of script into the recorded
automation script:
Pause until
Text("is warm")
InWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
The preceding lines of script instruct WinTask to pause execution of the automation
script until the text string is warm appears in notepad window. Once the text appears,
execution of the script continues following the EndPause statement. WinTask will wait
up to 120 seconds for the text to appear in notepad window before executing the error
- 19 -
handling script between the PauseFalse and EndPause statements. The user may wish
to override the default wait value of 120 seconds to 10 seconds by modifying the first
line of the script slightly as shown below. Also note that the error message presented
to the user has been changed from a generic automation script error to a system
specific error.
Pause 10 secs until
Text("is warm")
InWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
PauseFalse
MsgBox("The text is warm has not been typed in notepad")
End
EndPause
12.
To be sure that the Text Synchronization did work, add the line msgbox("The
text is now displayed") just after the line EndPause.
13.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. WinTask will now compile the script before running it. You
will be prompted to save the script. Enter the name scriptweb05 when the
Save As dialog is displayed. The Compilation results are displayed in the
Output window of the Editor and the compiled script starts its execution. The
text is seen in the Web page, the dialog box is displayed, click the OK button.
If the text to look for is within an icon, the text cannot be "seen" by the Text
Synchronization wizard. The OCR Text Synchronization method has to be used, it is
explained in the next exercise.
Exercise 6 : Synchronization on OCR Text
This exercise demonstrates how to invoke and use OCR Text Synchronization wizard
while recording an automation script, to wait for example that a text within an image
has been refreshed and then display a message.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. If WinTask opens a previously saved script (Ex. scriptweb05.src),
close the window by selecting menu item File/Close and click the New
button on the WinTask Toolbar or select menu item File/New.
2.
Click the Record button to start Recording Mode.
3.
When the Starting Recording Mode dialog box appears, check Internet
Explorer checkbox (or Mozilla Firefox checkbox if you prefer to use Firefox,
or Google Chrome checkbox if you prefer to use Chrome) and click the OK
button.
4.
The Launching Internet Explorer dialog box (or the Launching Mozilla
Firefox dialog box, or the Launching Google Chrome dialog box) will
- 20 -
appear. Enter www.wintask.com/demos/identicalpage1.htm into the
Web address field and click the OK button.
5.
The Web page titled Page Title will open, and WinTask will transform itself
into a floating toolbar titled WinTask Toolbar. Click the link here in the
Click here to go to the next page with the same title sentence.
6.
The Web page titled Page Title loads, it has the same title as the previous
one and you need to be sure that the text has finished to load before
capturing it.
7.
Invoke the OCR Text Synchronization wizard by clicking the OCR Text
Synchronization button
, on the WinTask Floating Toolbar, and select OCR
Text Synchronization. Recording mode is suspended.
- 21 -
8.
The Select the OCR engine field allows to choose the OCR engine ; choose
either the WinTask native OCR engine or the free one delivered by Microsoft,
engine called MODI (Microsoft Office Document Imaging).
9.
Click the Capture button on the OCR Text Synchronization wizard.
wizard will be hidden and the cursor will change to a crosshair.
The
10.
Use a drag box to capture the text A text synchronization in the body part
of the Internet Explorer window. The captured text is now displayed in the
Text field of the OCR Text Synchronization dialog box.
11.
Select some characters which are correctly recognized by the OCR engine
(using MODI, the text is perfectly recognized, using WinTask OCR engine,
some characters can be incorrect). Take only text word.
12.
Select text word, copy it, and paste it into the next field Copy from the
"Text" field… . The OCR Text Synchronization dialog box now looks like:
- 22 -
13.
Click Check button to verify that at replay the text will be recognized
correctly. The message OCR text recognized correctly should be displayed.
14.
Click Insert and Resume button. Recording mode resumes.
15.
Click the link previous page in the Come back to previous page sentence and
then close the browser window.
16.
Click the Stop Recording button on the WinTask Floating Toolbar to stop
Recording Mode.
- 23 -
If you use Internet Explorer, the OCR Text Synchronization wizard inserted the
following lines of script into the recorded automation script:
ret = UseOCREngine(1)
Pause Until
TextOCR("text")
InWindow("IEXPLORE.EXE|Internet Explorer_Server|Page Title - |1",2)
InArea(159,234,33,154)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
Note : if you use Internet Explorer 9, 10 or 11, replace the number 2 by 1 in the
InWindow line which becomes then:
InWindow("IEXPLORE.EXE|Internet Explorer_Server|Page Title - |1",1)
If you use Firefox, the OCR Text Synchronization wizard inserted the following lines of
script into the recorded automation script:
ret = UseOCREngine(1)
Pause Until
TextOCR("text")
InWindow("FIREFOX.EXE|MozillaWindowClass|Page Title - Mozilla Firefox",1)
InArea(159,234,33,154)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
- 24 -
The preceding lines of script instruct WinTask to pause execution of the automation
script until the text string text recognized by the OCR engine appears in Internet
Explorer window. Once the text appears, execution of the script continues following
the EndPause statement. WinTask will wait up to 120 seconds for the text to appear
in IE window before executing the error handling script between the PauseFalse and
EndPause statements. The user may wish to override the default wait value of 120
seconds to 20 seconds by modifying the first line of the script slightly as shown below.
Also note that the error message presented to the user has been changed from a
generic automation script error to a system specific error:
ret = UseOCREngine(1)
Pause 20 secs Until
TextOCR("text")
InWindow("IEXPLORE.EXE|Internet Explorer_Server|Page Title - |1",1)
InArea(159,234,33,154)
PauseFalse
MsgBox("The page took more than 20 seconds to load!")
End
EndPause
17.
To be sure that the Text Synchronization did work, add the line msgbox("The
text is now displayed") just after the line EndPause.
18.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. WinTask will now compile the script before running it. You
will be prompted to save the script. Enter the name scriptweb06 when the
Save As dialog is displayed. The Compilation results are displayed in the
Output window of the Editor and the compiled script starts its execution. The
text is seen in the Web page, the dialog box is displayed, click the OK button.
- 25 -
Exercise 7 : Window Synchronization
This exercise demonstrates how to invoke and use the Window Synchronization wizard
while recording an automation script, to wait until a File download from a Web page
has finished before opening it. Appendix C contains the solution for this exercise.
SKIP this exercise if you are using Internet Explorer 9 or Firefox as the File Download
automation does not need anymore a window synchronization.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. If WinTask opens a previously saved script (Ex. scriptweb06.src),
close the window by selecting menu item File/Close and click the New
button on the WinTask Toolbar or select menu item File/New.
2.
Click the Record button to start Recording Mode.
3.
When the Starting Recording Mode dialog box appears, check Internet
Explorer checkbox and click the OK button.
4.
The Launching Internet Explorer dialog box will appear.
Enter
www.wintask.com/demos into the Web address field and click the OK
button.
5.
The page titled WinTask Demonstration Pages will open, and WinTask will
transform itself into a floating toolbar titled WinTask Toolbar. Click the link
File in the page.
6.
A dialog box File Download will open. Click Save button.
7.
The Save As dialog box is displayed. In the filename field, type the file name
under which the file has to be saved. In order the script replays correctly
whatever current path is, type a filename including the full path, so for
example type c:\program files\wintask\scripts\test.test (if you use a
Windows x64 type c:\program files (x86)\wintask\scripts\test.test).
Do not automatize a path change using mouse clicks as it will be relative to
the current path – ALWAYS use an absolute path. Click the Save button.
8.
The script must wait until the Download complete window appears before
going on. Click the window synchronization icon
in the WinTask toolbar.
Window synchronization wizard will open and Recording mode is suspended.
- 26 -
9.
Click Spy button, the cursor will change to a crosshair. Move this cursor on
the title Download Complete (if the window is not yet displayed, wait until the
file has finished downloading). Click this window title. The Window
Synchronization dialog box comes back to focus.
- 27 -
10.
Check the Exists checkbox as the synchronization must wait until the window
exists. Check the Exact name match checkbox to force the exact recognition
of this Download complete window. Check Ignore instance checkbox to
make the script work whatever Internet Explorer windows are opened when
the script is replayed.
11.
The Window Synchronization waits for a maximum of 120 seconds that the
window exists before reporting an error if the window does not come up. If
the file download takes more than 120 seconds, change the value by checking
Use this time frame checkbox and type 150 for example. Check too the
Exists checkbox as the synchronization must wait until the window exists.
- 28 -
12.
Click Insert and Resume button. Recording mode resumes.
13.
Click the Close button of the Download complete window.
14.
Close the Internet Explorer window by clicking the close icon on the top right
.
15.
Click the Stop Recording button on the WinTask Floating Toolbar to stop
Recording Mode.
The Window Synchronization wizard inserted the following lines of script into the
recorded automation script:
Pause 150 secs Until
WinStatus (Exists, Exact)
InWindowAnyInstance("IEXPLORE.EXE|#32770|Download complete")
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
16.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. WinTask will now compile the script before running it. You
- 29 -
will be prompted to save the script. Enter the name scriptweb07 when the
Save As dialog is displayed. The Compilation results are displayed in the
Output window of the Editor and the compiled script starts its execution. The
script execution fails. Why ?
17.
Add at the end of the script the function deleting the file which already exists
using WinTask Kill function. Use WinTask help to find the correct syntax for
this function.
Synchronization waiting for a PDF file to be fully displayed
Exercise 8
This exercise deals with the case where the script downloads a PDF file from a Web
site and has to wait until it is fully displayed before using it. Appendix C contains the
solution for this exercise.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. If WinTask opens a previously saved script (Ex. scriptweb07.src),
close the window by selecting menu item File/Close and click the New
button on the WinTask Toolbar or select menu item File/New
2.
Click the Record button to start Recording Mode.
3.
When the Starting Recording Mode dialog box appears, check Internet
Explorer checkbox (or Mozilla Firefox checkbox if you prefer to use Firefox
or Google Chrome if you prefer to use Chrome) and click the OK button.
4.
The Launching Internet Explorer dialog box (or the Launching Mozilla
Firefox dialog box, or the Launching Google Chrome dialog box) will
appear. Enter www.wintask.com/manuals.php into the Web address
field and click the OK button.
5.
The page titled WinTask Manuals will open, and WinTask will transform itself
into a floating toolbar titled WinTask Toolbar. Click the link Tutorial in the
body part of the page.
6.
The Tutorial book is displayed, tutorial.pdf. Before recording any action in the
Acrobat Reader window, the script must wait until all the book is displayed.
The easiest synchronization is a Time Synchronization, adding a fixed pause,
waiting enough seconds to be sure that the book is fully loaded. A more
elaborate synchronization would be an OCR Text Synchronization waiting for a
text within the window telling that the pdf file has finished loading.
- 30 -
7.
Invoke
the
Time
Synchronization
Synchronization button
Mode will be paused.
wizard
by
clicking
the
on the WinTask Floating Toolbar.
Time
Recording
8.
Change the default time delay of 10 seconds to 60 seconds.
9.
And click the Insert and Resume button. Recording Mode will become active
again.
10.
Come back to the page listing all the available WinTask books by clicking the
Back icon in the browser.
11.
The page titles WinTask Manuals is displayed again.
12.
Close the browser window by clicking the close icon on the top right
13.
Click the Stop Recording button on the WinTask Floating Toolbar to stop
Recording Mode.
- 31 -
.
The Time Synchronization wizard inserted the following line of script into the recorded
automation script:
Pause 60 secs
14.
Click the Play button
on the WinTask Toolbar to replay the actions listed
in the script. WinTask will now compile the script before running it. You will be
prompted to save the script. Enter the name scriptweb08 when the Save As dialog
is displayed. The Compilation results are displayed in the Output window of the
Editor and the compiled script starts its execution. The script execution fails. Why ?
TIP: The click on the Back icon in the browser window is not recorded. Use the
PreviousPage() WinTask function, so add this line
PreviousPage()
And this line will press Back button at replay in any browser.
This section has described the WinTask Synchronization wizards and presented how to
use some of them. The remaining wizards are similar in use and should prove to be
intuitive to the user familiar with the other wizards.
- 32 -
Wi n Ta s k S c r i p t i n g L a n g u a g e
The WinTask Scripting Language has a program structure similar to Microsoft Visual
BasicTM and other scripting languages. WinTask automation scripts must be structured
correctly to avoid compiler errors. WinTask scripts are composed of three distinct
sections. The first section is reserved for data arrays, the second for user-defined
functions and subroutines, and the final section for the main program. Other features
of the script language include variables, integers and strings, arrays of integers and
arrays of strings.
Automation scripts generated during Recording Mode fall into the category of main
program script.
The user can wrap repetitive blocks of script in functions or
subroutines that can then be called from other function/subroutines or the main
program.
Language Functions
Functions support one or more input parameters and a single return value. Both are
optional. If a function has input parameters, they follow the function name as a
comma separated list enclosed in parenthesis. Constant strings passed to functions
must be enclosed in double quotes (Ex: "qwerty"). Functions that return a string
must have a function name which ends with $. Functions that return an integer
CANNOT have a function name which ends with $. Below is an example:
StartBrowser("IE", "www.wintask.com",3)
- 33 -
The Insert Statement dialog can be invoked by clicking the Language button
on the WinTask Toolbar. The Insert Statement dialog presents all of the predefined
functions and system variables available in the WinTask Scripting Language in a tree
structure. Clicking an item in the list labeled with a plus sign will expand that item.
Expanded items, designated by a minus sign, can be collapsed by clicking the item.
Double clicking any other item will invoke the context sensitive help or a wizard for the
selected function or system variable. A right click on a statement displays a context
menu. If you check Show wizard checkbox, a double click on a statement displays a
dialog box where you can type directly the parameters for this function. In the
Language list, all the Web functions are under the chapter Web functions.
The Insert Statement dialog provides an easy way to drill down into the help system
to locate the function(s) that can fine-tune your script. Please take a few minutes to
search the WinTask Help System to learn more about the available functions.
- 34 -
Variables
The WinTask Scripting Language supports variables that allow commonly used values
to be stored in memory for later use by the compiled script as it executes. Using
variables is as easy as specifying the name of the variable and assigning a value.
Except for arrays, variables do not need to be declared before use. Consider the
following line of script:
Read("file.txt", line$, crlf)
The Read function will open the file file.txt and reads the first line of the file into a
string variable named line$. The script can then extract the desired information from
the string contained in the line$ variable. As with Functions that return a string, string
variable names must end with the $ character. It should be noted that this line of
script is self-sufficient and is not dependent on any other line of script.
Another example demonstrating the use of variables:
url$ = "http://www.wintask.com"
StartBrowser("IE",url$)
StartBrowser("IE","http://www.wintask.com")
The first two lines are equivalent to the third line of script. At first it seems easier to
just use the third line of script instead of the first two lines. However if the script
needs to make numerous references to the Web url http://www.wintask.com, the first
two lines are the better choice. Succeeding references to http://www.wintask.com
can be replaced with the string variable url$.
System Variables
WinTask uses a set of system variables that define the default behavior of the
Executor when executing an automation script. For example, if a Web page loads
slowly, the script can compensate by modifying the appropriate system variable to
modify the default behavior to wait for a longer period of time before reporting an
error.
All system variables start with the # character. See the WinTask Help System for
further details on the available system variables and the appropriate values to modify
the default behavior of the Executor. The following is an example of a system
variable:
#IgnoreErrors = 1
Integers
Integer values in the WinTask Scripting Language range from –2,147,483,648 to
+2,147,483,647 inclusive. Integer variable names cannot end with the $ character.
- 35 -
Strings
Strings can contain any number of characters. Empty strings (zero length) are also
valid. An empty string is "", a string with just a space is " ". String variable names
must end with the $ character. The following is an example of a string being assigned
to a string variable:
Greeting$ = "Hello, how are you?"
Reals
Real values are not supported in WinTask. They have to be stored as strings and
Add$, Divide$, Multiply$, Subtract$ functions allow operations on reals. Here is an
example:
Real1$ = "135.46"
Real2$ = "-10.46"
Result$=Add$(Real1$,Real2$)
Msgbox(Result$)
Arrays
One dimension arrays are supported in WinTask. They have to be declared at the very
beginning of the script using the Dim function. The maximum size of an array is
65535. The first element of an array starts at index 0. Here is an example declaring an
integer array of 1001 elements:
Dim Data(1000)
Here is an example declaring a string array of 1001 elements:
Dim Data$(1000)
Operators
The WinTask Scripting Language supports assignment, arithmetic operators, logical
operators and a string concatenation operator. Operators take an argument on either
side and can be combined into longer combinations. Logical operators are used in
conjunction with conditional statements such as If, While and Repeat. Most of the
operators are listed below with sample usage. See the WinTask Help System for a
comprehensive list.
= Assignment: Assign one value to a variable
count = 38
name$ = “John Q. Public”
+ Arithmetic Addition
rows = lines + 7
- Arithmetic Subtraction
Profit = Gross - Expenses
- 36 -
* Arithmetic Multiplication
Fingers = Hands * 5
/ Arithmetic Division
Hours = Days / 24
= Logical Equal To
If (employees = 15) Then ... Endif
<>
Logical Not Equal To
If (employees <> 15) Then ... Endif
< Logical Less Than
While (employees < 15) ... Wend
<=
Logical Less Than or Equal To
If (employees <= 15) Then ... Endif
> Logical Greater Than
Repeat ... Until (employees > 15)
>=
Logical Greater Than or Equal To
If (employees >= 15) Then ... Endif
AND
Logical AND
If (employees = 15) AND (desks < 10) Then ... Endif
OR
Logical OR
If (employees <> desks) OR (employees <> computers) Then ...
Endif
+ String Concatenation
FullName$ = FirstName$ + LastName$
Title$ = “President and CEO ” + FullName$
- 37 -
- 38 -
We b P a g e M a n a g e m e n t F u n c t i o n s
The WinTask Script Language contains several mechanisms to control the behavior of
the WinTask Executor when attempting to locate and identify Web pages within the
browser at run-time. Several of the more important system variables and functions
are described in this chapter.
#IgnoreErrors
The #IgnoreErrors system variable controls how run-time errors are handled during
the execution of a function in an automation script. By default the variable is set to 0
which terminates the script and displays an error message whenever the WinTask
Executor encounters an error. Setting the variable equal to 1 allows execution to
continue if the function fails. In this circumstance, the function returns an error code
that can be tested by the script and the appropriate action taken.
The following block of code illustrates how the #IgnoreErrors system variable may
be used:
#IgnoreErrors = 1
ret = StartBrowser("IE","www.wintask.com")
If (ret = 0) Then
MsgBox("WinTask Web site has been launched successfully ")
Else
MsgBox("Could not load WinTask Web site!”)
Endif
#IgnoreErrors = 0
The above code will display a message after attempting launch to
www.wintask.com. The message that is displayed depends upon the value returned
by the StartBrowser function.
#ActionTimeout
The #ActionTimeout system variable controls how long the WinTask Executor will
wait before reporting a run-time error when selecting a Web page, clicking a link,
typing in a form field. The variable can be used to shorten or lengthen the amount of
time waited before reporting an error. The default value is 30 seconds.
- 39 -
The following block of code illustrates how the #ActionTimeout system variable may
be used:
StartBrowser("IE", "www.wintask.com/demos")
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'Page 2']")
#ActionTimeout = 5
#IgnoreErrors = 1
ret=UsePage("Page 2")
If (ret = 0) Then
MsgBox("Page 2 did load in less than 5 secs")
Else
MsgBox("Buy a faster PC!")
Endif
#ActionTimeout = 30
UsePage functions returns an error if the specified page is not found after 5 seconds.
To avoid that script execution stops in case the page does not load within 5 seconds,
note the use of #IgnoreErrors=1. The return code of UsePage is then tested and the
displayed message depends on the value of the return code.
#UsePageExact
The #UsePageExact system variable controls the way a page is found at replay.
Consider those two lines:
UsePage("WinTask – Welcome!")
UsePage("WinTask - Form")
At replay, the two lines look for a page starting with WinTask word.
The default behavior of WinTask at replay is to look for a page which title is exactly
the same as the one specified in the UsePage line. If an exact match is not found, an
approached match starts : the rightmost characters of the page title are truncated
until at least the first character of the page matches the first character of the page
specified in the UsePage function. If even the first character does not match, an error
is reported.
This way of finding a Web page can be changed using the #UsePageExact system
variable and assigning it to 1. If a line #UsePageExact = 1 is encountered in the
script, the next pages are found only if their title is exactly the same as the one
specified in the UsePage line. To come back to the default value, insert the line
#UsePageExact = 0. Then for the next UsePage functions, the approached way of
finding pages will be used (which is the default behavior).
TIP:
The approached search can slow down a bit the script execution. If a page
title varies from one execution to another, but its first characters are
always the same, you can truncate in the UsePage line the rightmost
characters
which are
changing. In our example, the line :
- 40 -
UsePage("WinTask - ), will find the page at replay whatever word Welcome
or Form is behind the WinTask word.
TIP:
If different pages of the same Web site are displayed simultaneously and if
the page titles begin all by the same characters, the approached search
can lead to a wrong page identification at replay. In this case, force
#UsePageExact to 1.
Exercise 9 : Using different Web functions and managing variables
This exercise is a programming exercise demonstrating the use of different Web
functions and variables. Appendix C contains the solution for this exercise.
This exercise uses Internet Explorer and its command bar. If under Internet Explorer
9/10/11, your command bar is not displayed, right click on an empty space on the
toolbar, and click on Command Bar to make it display.
1.
Go manually to the c:\program files (x86)\wintask\scripts directory (or under
c:\program files\wintask\scripts if you use a Windows 32 bit version) and
delete the test.test file if it exists.
2.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. Click the New button on the WinTask Toolbar or select menu item
File/New if Untitled1 is not displayed.
3.
Click the Record button to start Recording Mode. When the Starting
Recording Mode dialog box appears, check Internet Explorer checkbox
and click the OK button.
4.
The Launching Internet Explorer dialog box will appear.
Enter
www.wintask.com/demos into the Web address field and click the OK
button.
5.
The Web page titled WinTask Demonstration Pages will open, and WinTask
will transform itself into a floating toolbar titled WinTask Toolbar. Click the
link Page 2 in the body part of the page.
6.
The Web page titled Page 2 is now displayed.
7.
Select in the command bar the menu item Page and select Save as option.
8.
The Save Webpage dialog box is displayed. In the file name field, type the
file name under which the webpage has to be saved. In order the script
replays correctly whatever current path is, type a filename including the full
path,
so
for
example
type
c:\program
files
(x86)\wintask\scripts\test.test (if you use a 32 bit Windows, the wintask
folder is under c:\program files). Do not automatize a path change using
mouse clicks as it will be relative to the current path – ALWAYS use an
absolute path. Click the Save button
- 41 -
9.
Close the Internet Explorer window by clicking the Close icon
top right of the Internet Explorer window.
at the
10.
Click the Stop Recording button
Recording Mode.
11.
WinTask Editor window comes back to focus, modify the generated script in
order
to
replace
the
filename
"c:\program
files
(x86)\wintask\scripts\test.test” by a variable named filename$.
At the
beginning of the script, initialize this variable with the value "c:\program files
(x86)\wintask\scripts\test.test".
12.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. WinTask will now compile the script before running it. You
will be prompted to save the script. Enter the name scriptweb09a when the
Save As dialog is displayed. The Compilation results are displayed in the
Output window of the Editor and the compiled script starts its execution.
13.
Script execution does not go to its end because the test.test file already
exists. Click the OK button on the message box displaying the error message.
14.
Modify the script to automatize the click on the Yes button in the Confirm
Save as dialog box : in the WinTask Editor window, move the cursor just
after the line
Click(Button,"&Save") and click the Record icon in the
WinTask toolbar. Check Nothing and click the OK button. While you are in
Recording mode, click the Yes button and stop Recording mode.
15.
Add an If…EndIf block in order to click the Yes button only if the Confirm
Save as window appears. Use for that the ExistW function.
16.
Save the modified script under the scriptweb09b name, and start its
execution clicking the Play icon.
17.
Now delete the ExistW line, assign the system variable #IgnoreErrors to 1,
and test the return code of the UseWindow function which looks for the
window named Confirm Save as. Modify the If block in order to test now the
return code of the UseWindow line in this If structure and click Yes button
only if the UseWindow succeeds.
18.
Save the modified script under the scriptweb09c name. Start its execution.
19.
In the first line of the script where the filename$ variable is assigned to
"c:\program files (x86)\wintask\test.test”, modify so the variable will take
now the value "c:\program files (x86)\wintask\demo09d.test”. (or under
Windows 32 bit "c:\program files\wintask\demo09d.test”).
20.
Save the modified script under the scriptweb09d name. Start its execution.
21.
Questions for Discussion: the technique used at step 19 takes more time to
execute than the one in step 17. However, which system variable could be
used to detect the UseWindow failing faster?
- 42 -
on the WinTask Floating Toolbar to stop
This exercise illustrates that there is usually more than one way to solve a run-time
problem. Any task that is to be automated will present it’s own unique challenges.
With some experience, the correct solution will become readily apparent.
- 43 -
- 44 -
Iteration
The WinTask Scripting Language provides two mechanisms to repetitively execute the
same block of script. The While/Wend construct is used to execute the block of script
zero or more times. The Repeat/Until construct executes the block one or more
times.
Iteration
The following sample script illustrates the syntax for the While/Wend and the
Repeat/Until statements.
Start = 0
End = 10
Index = Start
While (Index < End)
Functions and/or other code to be executed repetitively
Index = Index + 1
Wend
Start = 0
End = 10
Index = Start
Repeat
Functions and/or other code to be executed repetitively
Index = Index + 1
Until (Index >= End)
In both cases, the start and end points for the loops are set to zero and ten
respectively. The code in both constructs will be executed ten times. Notice that the
Boolean expressions are different in the two constructs yet they achieve the same
result.
Exercise 10 : Iteration for clicking the ith page
This programming exercise demonstrates how a script can be modified to repeat a
block of script several times. Recording mode is first used to generate the block of
lines to iterate, then you will be asked to modify the generated script based upon
WinTask iteration features. Appendix C contains the solution for this exercise.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
- 45 -
button. Click the New button on the WinTask Toolbar or select menu item
File/New if Untitled1 is not displayed.
2.
Click the Record button to start Recording Mode. When the Starting
Recording Mode dialog box appears, check Internet Explorer checkbox (or
Mozilla Firefox checkbox or Google Chrome checkbox) and click the OK
button.
3.
The Launching Internet Explorer dialog box (or the Launching Mozilla
Firefox/Google
Chrome
dialog
box)
will
appear.
Enter
www.wintask.com/demos/page-iteration1.htm into the Web address
field and click the OK button.
4.
The page titled Page Iteration 1 will display. In the right part of browser
window, you can see the links to go to the pages 2, 3, 4,…. In this exercise,
you will write a script which displays the pages 1 to 7.
5.
Click the 2 link. The page titled Page Iteration 2 will display. Click here link
in the Click here to load Page iteration 1 sentence. The page titled Page
Iteration 1 is displayed again.
6.
Close the browser window by clicking the Close icon
of the browser window.
7.
Click the Stop Recording button
Recording Mode.
8.
In the WinTask Editor window, modify the script and use the While/Wend
construction to click links from 2 to 7. Two lines have to be modified to take
into account the floating index, not 2 any more but i iterating from 2 to 7:
at the top right
on the WinTask Floating Toolbar to stop
ClickHTMLElement("A[INNERTEXT= '2']")
UsePage("Page Iteration 2")
TIP:
Use the string concatenation operator (+) to construct the string to be
written as parameter for the ClickHTMLElement and UsePage functions. As
the index i is an integer, use the Str$ function to convert the integer to a
string before concatenating with the + sign.
9.
Save the modified script under the scriptweb10a name. Start its execution.
You should see the script click the 2 page number, go to page 2, then click the
Home page link, display page 1, then click the 3 page number, and so on.
10.
At the beginning of the script, insert the line #UsePageExact=1. Why this line
is important for a reliable replay of the script?
11.
Modify the script to replace the Repeat/Until block by a While/Wend block.
12.
Save the modified script under the scriptweb10b name. Start its execution.
After completing this exercise, you will be able update a script to execute repetitive
tasks without copying the same block of code numerous times.
- 46 -
File Functions
The WinTask Script Language provides several functions that perform read and write
operations in text files, Excel files, XML files and INI files. Several of the more
important file functions used in Web automation scripts are described in this chapter.
Additional file functions and specific details on the functions described in this chapter
can be found by double-clicking the File management instructions chapter in the
Language window of the WinTask Editor (the window on the right, if the window is not
displayed, press F4 to display it).
Exist()
The Exist function is used to determine whether a particular file exists on the
computer at run-time. The function accepts a full pathname, a UNC (Universal
Naming Convention), or a file from the current working directory. The function
returns a value that can be used in conjunction with conditional statements. Use this
function to avoid run-time errors due to files that can’t be located.
The following block of code illustrates how the Exist function may be used:
FileName$ = "C:\Program Files (x86)\WinTask\Bin\TaskBox.exe"
ret = Exist(FileName$)
If ret = 1 Then
Shell(chr$(34)+FileName$+chr$(34))
Else
MsgBox("Cannot find file: " + FileName$)
Endif
TIP: The filename passed to the Exist function should not be surrounded by double
quotes (Chr$(34)) as required by the Shell function. The quotes should not be
supplied even if the filename contains embedded spaces.
Kill()
The Kill function is used to permanently remove a file from the computer at run-time.
The function accepts a full pathname, a UNC, or a file from the current working
directory.
The function returns a value that can be used in conjunction with
conditional statements.
The following block of code illustrates the Kill function, note the use of
#IgnoreErrors=1 to avoid a runtime error if the file does not exist when Kill is
invoked:
- 47 -
FileName$ = "C:\Temp\SomeUselessFile.txt"
#IgnoreErrors=1
ret = Kill(FileName$)
If ret = 0 Then
MsgBox("File: " + FileName$ + " has been deleted.")
Else
MsgBox("Cannot delete file: " + FileName$)
Endif
#IgnoreErrors=0
Read() et Write()
The Read function is used to read the contents of a text file from the computer’s file
system. The Write function is used to write data in a text file. Those functions are not
described in this book because Web automation scripts do not use them usually but
instead use ReadExcel and WriteExcel. Read and Write functions are described in the
WinTask book for Windows automation.
ReadExcel et WriteExcel
The WinTask Script Language provides two functions that interface to Microsoft
ExcelTM allowing the script developer to read and write Excel formatted files (.XLSx or
.XLS for Excel 2003). The function accepts a full pathname, a UNC, or a file from the
current working directory. Microsoft Excel must be installed for these functions to
execute properly
The ReadExcel function is used to read a block of consecutive cells from an Excel
spreadsheet file. The cells read from the spreadsheet must be either in the same row
or the same column. The spreadsheet can be open in Excel when reading from the
Excel file.
The WriteExcel function is used to write a block of consecutive cells to an Excel
spreadsheet file. The cells written to the spreadsheet must be either in the same row
or the same column. The spreadsheet cannot be open in Excel when writing to the
Excel file. The function cannot create an Excel spreadsheet file and as such is
restricted to modifying existing files (WinTask includes the CreateExcelFile function
to create a new Excel file).
The two functions have the following syntax:
ret = ReadExcel(ExcelFileName$, CellRangeDesc$, CellStrArray$())
ret = WriteExcel(ExcelFileName$, CellRangeDesc$, CellStrArray$())
The ExcelFileName$ parameter specifies the name of the Excel spreadsheet file.
The CellRangeDesc$ parameter specifies which cells are to be read or written. The
string passed to the function is composed of two parts: a sheet descriptor and a cell
descriptor separated by an exclamation (Ex. "Sheet1!A9:F9"). The sheet descriptor
can be omitted if the spreadsheet only contains one sheet.
The string
- 48 -
“Expenses!B3:B5” will read the cells in column B, rows 3 through 5 on the sheet
labeled Expenses. The string “D8:H8” will read the cells in row 8, columns D through
H on the first sheet regardless of it’s name.
The CellStrArray$() parameter specifies a string array which is to receive or supply
the cell data. The cell data is stored in consecutive locations in the array starting at
location 0. The string array must be declared at the beginning of the script using the
DIM statement.
- 49 -
- 50 -
We b D a ta C a p t u re F u n c t i o n s
The CaptureHTML and CaptureTableHTML WinTask functions allow to capture data
from a Web page. The Capture Wizard can be used to extract easily data from a Web
page and store them in an Excel file. Following exercise illustrates the capture
process.
Exercise 11 : Web data extraction
This programming exercise demonstrates how to extract data from a Web page and
store them in an Excel file. Appendix C contains the solution for this exercise.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. Click the New button on the WinTask Toolbar or select menu item
File/New if Untitled1 is not displayed.
2.
Click the Record button to start Recording Mode. When the Starting
Recording Mode dialog box appears, check Internet Explorer or Mozilla
Firefox checkbox or Google Chrome checkbox and click the OK button.
3.
The Launching Internet Explorer or Launching Mozilla Firefox or
Launching
Google
Chrome
dialog
box
will
appear.
Enter
www.wintask.com/demos/data.htm into the Web address field and click
the OK button.
4.
The page titled Capture Data from a Web Table is displayed. The script has
to capture the content of the three columns, Name, Email and Phone, and
then write the extracted data in three columns of an Excel file.
5.
Click the Capture button
on the WinTask Floating Toolbar to call the
Capture Wizard. Recording mode is suspended.
- 51 -
6.
Click Spy button in the Capture Wizard dialog box. The mouse cursor
becomes an hourglass.
7.
Move the mouse cursor above the table to capture, a black rectangle
surrounds the table when the mouse is on it. Click and the captured data are
now displayed in the Capture Wizard dialog box.
- 52 -
8.
Click Next button. The Specify the HTML element where the data to be
captured are dialog box is displayed. Just click Next button. The Select the
data you want to capture dialog box is now displayed.
- 53 -
9.
Select C1 to C3 columns using the mouse.
- 54 -
10.
Click Next button. The Specify where to copy the captured data is
displayed. By default, the data are copied to Excel, so just click the Next
button.
- 55 -
11.
The Specify the Excel file where to copy the extracted data dialog box is
displayed. In the Excel file field, type an Excel filename, including the full
path, for example c:\program files (x86)\wintask\scripts\data.xlsx (or xls
extension if Excel 2003 is used – if the Excel file does not exist, it will be
created).
- 56 -
12.
Click Paste into the script button.
13.
Recording mode resumes. Close the browser window.
14.
Click the Stop Recording button
Recording Mode.
- 57 -
on the WinTask Floating Toolbar to stop
The Capture Wizard has written 3 lines at the beginning of the script:
Dim tabcell_2$(100)
Dim tabcell_1$(100)
Dim tabcell_0$(100)
Those 3 Dim lines declare the string arrays which will be used later in the script to
store the captured data. One array stores one column (WinTask supports one
dimension array, not multi-dimension). The names generated are generic names, you
can change the names to reflect the name of the captured data (for example Dim
Name$(100) instead of Dim tabcell_0$(100)).
The Capture Wizard has generated too the Capture lines:
ret = CaptureTableHTML("TABLE[CONTENT='Name']", "R1C1:R6C1", tabcell_0$())
ret = WriteExcel("c:\program files (x86)\wintask\scripts\data.xls",
"Sheet1!A1:A6", tabcell_0$())
ret = CaptureTableHTML("TABLE[CONTENT='Name']", "R1C2:R6C2", tabcell_1$())
ret = WriteExcel("c:\program files (x86)\wintask\scripts\data.xls",
"Sheet1!B1:B6", tabcell_1$())
ret = CaptureTableHTML("TABLE[CONTENT='Name']", "R1C3:R6C3", tabcell_2$())
ret = WriteExcel("c:\program files (x86)\wintask\scripts\data.xls",
"Sheet1!C1:C6", tabcell_2$())
It is 3 times the same structure to capture 3 columns. The CaptureTableHTML line
captures the Web Table specified by the label of the first column,
"TABLE[CONTENT='Nom']", captures cells R1C1 to R6C1, so column C1 (first column)
and 6 lines and stores those data in the string array named tabcell_0$() declared
before using the Dim statement. The ret= at the beginning of the line returns an
integer giving the number of data extracted and the number of data written to Excel.
15.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. WinTask will now compile the script before running it. You
will be prompted to save the script. Enter the name scriptweb11 when the
Save As dialog is displayed. The Compilation results are displayed in the
Output window of the Editor and the compiled script starts its execution.
16.
Open the c:\program files (x86)\wintask\scripts\data.xlsx Excel file.
You can see the automatically extracted data.
- 58 -
A u t o m a t i c We b F o r m F i l l i n g
Data entry in a Web form can be automatized by a WinTask script generated by
Recording mode. The different fields of the form are specified by their individual HTML
descriptor generated automatically by Recording mode. If you want to know more
about how is built such an HTML descriptor, look in the help for the sentence HTML
Descriptor.
Data entry automation in a Web form becomes very efficient when an iteration is used
along an external data file : the script reads one record in the file, types the data in
the different fields of the form, clicks the Submit button and processes the next
record. The external data file is usually an Excel file.
The next two exercises demonstrates how to create such an automatic data entry
process, first using Recording mode to create a script typing constants in a Web form,
second to modify the previous template adding the iteration and the use of an
external file instead of typing constants.
Exercise 12 : Typing constants in a Web form
This programming exercise demonstrates how to type automatically constants in a
Web form. Appendix C contains the solution for this exercise.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. Click the New button on the WinTask Toolbar or select menu item
File/New if Untitled1 is not displayed.
2.
Click the Record button to start Recording Mode. When the Starting
Recording Mode dialog box appears, check Internet Explorer checkbox (or
Mozilla Firefox checkbox or Google Chrome checkbox) and click the OK
button.
3.
The Launching Internet Explorer dialog box (or the Launching Mozilla
Firefox/Launching Google Chrome dialog box) will appear.
Enter
www.wintask.com/demos into the Web address field and click the OK
button.
4.
The page titled WinTask Demonstration Pages is displayed. Click the Form
link in the page.
5.
The page Form is displayed. In the Name field, type SMITH ; in the E-mail
field, type [email protected] ; in the Phone field, type 820123456 and
finally click the Clear button.
6.
Close the browser window.
- 59 -
7.
Click the Stop Recording button
Recording Mode.
on the WinTask Floating Toolbar to stop
The generated script, even simple, has three parts which are always there in a script
automatizing data entry. The first part launches the Web site and navigates to the
page where the form is displayed. The second part fills the form. The last part exits
the site (typically a logout before closing the browser). In this exercise, the second
part uses the WriteHTML function to type constant data:
WriteHTML("INPUT TEXT[NAME= 'name']", "SMITH")
WriteHTML("INPUT TEXT[NAME= 'email']", "[email protected]")
WriteHTML("INPUT TEXT[NAME= 'phone']", "820123456")
The three lines have the same structure, the first parameter of the WriteHTML
function specified the HTML descriptor for the field where to type, so for example
"INPUT TEXT[NAME= 'name']" for the field which internal HTML name is name. The
second parameter is the data, a string, to type in the field, for example "SMITH".
The line just after:
ClickHTMLElement("INPUT RESET[VALUE= 'Clear']")
automatizes the click on the Clear button.
Again, all those lines are generated automatically by Recording mode and you don't
have to understand the precise syntax for the HTML descriptors.
8.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. WinTask will now compile the script before running it. You
will be prompted to save the script. Enter the name scriptweb12 when the
Save As dialog is displayed. The Compilation results are displayed in the
Output window of the Editor and the compiled script starts its execution.
9.
The Web site opens, the form page is displayed, the three fields are filled fast,
the Clear button is clicked and the browser is closed.
Exercise 13 : Typing data read in an Excel file in a Web form
This programming exercise demonstrates how to modify the script written in Exercise
12 in order to fill the form with the data read in the Excel file created by the Web
extraction process used in Exercise 11. Arrays and an iteration are used. As usual,
Appendix C contains the solution for this exercise.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. If the script scriptweb12 script is displayed, go to step 3. If not,
select the File/Close All menu item.
- 60 -
2.
Click the Open button
scriptweb12.src file.
on
the
WinTask
Toolbar
and
open
the
3.
In the WinTask Editor window, select the File/Save as menu item. In the
Save as dialog box, save under the scriptweb13a.src. This step allows to
keep scriptweb12.src script as it was at the end of the exercise 12.
4.
Before launching the Web site, the script must read the data in the Excel file
and populate three arrays witht those data. The first array is named Name$,
the second Email$ and the third Phone$.
5.
At the very beginning of the script, add the three DIM lines to declare the 3
arrays.
6.
Just after those DIM lines, add the assignment of a variable filename$
containing the Excel filename to read:
filename$= "c:\program files\wintask\scripts\data.xls"
If you use Excel 2007 or Excel 2010, the line is:
filename$= "c:\program files\wintask\scripts\data.xlsx"
If you use a x64 Windows and Excel 2007 or Excel 2010, the line is:
filename$= "c:\program files (x86)\wintask\scripts\data.xlsx"
7.
Add then the three ReadExcel lines reading each column of the Excel file and
populating the corresponding array. Note that the first line of the Excel file
contains the column labels which must not be sent to the Web form, so read
from A2 and not from A1. The first ReadExcel line is then:
ReadExcel(filename$,"A2:A6",name$())
8.
After the three ReadExcel lines, the loop must be inserted and the second
parameter of each WriteHTML line must be replaced by the array element to
type in the corresponding field.
9.
As the first element of an array starts at index, the loop starts at index i=0.
10.
Start the loop structure by while i < 5 as there are 5 elements from 0 to 4 in
each array (a condition to end the loop without knowing the size of the array
is seen at the end of this exercise).
11.
In the WriteHTML lines, replace the constant by the element i of the array. For
example,
WriteHTML("INPUT TEXT[NAME= 'name']", "SMITH")
becomes
WriteHTML("INPUT TEXT[NAME= 'name']", name$(i))
12.
After you have modified the three WriteHTML lines, add after
ClickHTMLElement line the incrementation of the index i, so i = i + 1
- 61 -
the
13.
End the loop by the Wend line. This line must be before the line CloseWindow
which closes the browser window.
14.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. WinTask will now compile the script before running it.
15.
The Web site opens, the form page is displayed, the three fields are filled fast,
the Clear button is clicked, the next three data are filled, the Clear button is
clicked and so on. At the end, the browser is closed.
16.
In the WinTask Editor window, select File/Save as menu item. In the Save
as dialog box, save as the current script under the name scriptweb13b.
17.
Replace the condion while i < 5 for exiting the loop by a condition which exits
the loop if name$(i) is empty (an empty string is "").
18.
Run the new version of the script.
Other functions for Web forms automation
Web Forms can display listboxes and the automation script must be able to select an
item in the list.
The SelectHTMLItem function selects an item in a list displayed on a Web page. For
example, on the Form page, this line:
SelectHTMLItem("SELECT[NAME= 'subject']", "Future enhancement")
selects "Future enhancement" from the HTML list named HTML subject.
The SelectedHTMLItem$ returns the item in the list which has been selected. On the
same Form page, here is an example:
Selected_value$=SelectedHTMLItem$("SELECT[NAME= 'subject']")
The content of the variable selected_value$ is the item in the list named subject which
has been selected.
The ListHTMLItem$ function returns the nth item in the specified list. Numerotation
starts at 0. On the Form page, this line:
list_value$=ListHTMLItem$("SELECT[NAME= 'subject']",3)
returns in list_value$ the content of the 4th item of the list for the HTML list named
subject.
The CheckedHTML function returns the status of a radio button or checkbox. This
line tests if the Urgent request checkbox is checked or not in the Form page:
- 62 -
status=CheckedHTML("INPUT CHECKBOX[NAME= 'contactsoon']")
The integer variable statut contains 1 if the checkbox named contactsoon (HTML name
for the Urgent request checkbox) is checked, 0 if not.
The GetHTMLEditText function captures the content of a form field. Here is an
example on the WinTask – Form page to capture the content of the field named
Name.
GetHTMLEditText("INPUT TEXT[NAME= 'name']", a$)
The string variable a$ contains the text displayed in the field name.
The PreviousPage function presses the Back button in the current browser within the
current Tab:
PreviousPage()
- 63 -
- 64 -
S u b ro u t i n e s a n d F u n c t i o n s
This chapter involves programming skills. It explains how to create structured
automation scripts.
The WinTask Script Language provides many pre-defined functions that make the job
of automating a task much easier. As one becomes more proficient with the
language, they will undoubtedly recognize that similar functionality is repeated over
and over when scripts are being written. The WinTask Script Language supports
Subroutines and Functions that allow the script developer to consolidate common
functionality. Coding Best Practices recommend the use of Subroutines and Functions
to promote code reuse and to make automation script development more efficient.
Sub...EndSub
The syntax for the Sub, ExitSub and EndSub statements is as follows:
Sub <sub_name>([<param1>[, <param2>] ...])
<statements>
ExitSub
<statements>
EndSub
At a minimum, a Subroutine consists of a block of script statements surrounded by the
Sub and EndSub statements. The ExitSub statement is typically used in conjunction
with a conditional statement to leave the Subroutine before reaching the EndSub
statement. The name of the Subroutine is specified by <sub_name> and should be
both descriptive and unique. Subroutines can also accept optional parameters, as
designated by <param1>, which the Subroutine can perform operations on. The
name of each parameter is a valid variable until the EndSub statement. Strings
passed to the Subroutine should end with the $ character.
TIP:
Make sure the parameter names are different from any variables used
elsewhere in the script. Since variables are global in scope (unless you use
LOCAL statement), defining a parameter with the same name as a variable
can lead to confusion as to which one (variable or parameter) is being
referenced in the Subroutine.
TIP:
Make sure the Subroutine appears in the script file before attempting to
invoke it.
- 65 -
Converting a Script into a Subroutine
Any collection of script statements can be wrapped into a Subroutine that can be used
several times during the automation of an application or task. The actual effort
requires no more than a little planning to decide the scope of the Subroutine, it’s input
parameters, adding the Sub and EndSub statements, and finally invoking the
Subroutine with the appropriate parameters.
Exercise 14 : Converting a Script into a Sub
This exercise creates a script which downloads Web images. Then the script is
converted to a Sub. A new function SavePictureAs is used in this exercise. Appendix C
contains the solution for this exercise. As SavePictureAs is available only for Internet
Explorer, this exercise does not apply if you use Firefox.
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. Click the New button on the WinTask Toolbar or select menu item
File/New if Untitled1 is not displayed.
2.
Click the Record button to start Recording Mode. When the Starting
Recording Mode dialog box appears, check Internet Explorer checkbox
and click the OK button.
3.
The Launching Internet Explorer dialog box will appear.
Enter
www.chambre-portbail.fr into the Web address field and click the OK
button.
4.
The Welcome page will display. Click the Galerie Photos link in the top
menu.
5.
Click the first photo. Close the Internet Explorer window. Click the Stop
Recording button
Mode.
on the WinTask Floating Toolbar to stop Recording
6.
One ClickHTMLElement line has been generated for the click on the photo. In
order to save this photo on disk, you need to replace the ClickHTMLElement
function by the SavePictureAs line. The SavePictureAs function uses as second
parameter the name of the folder under which the image is saved, and as
third parameter, the name of the file under which the image is saved.
7.
In this exercise, you will save the images under the directory c:\test, so if this
folder does not exist, create manually the folder C:\test. Modify then the
ClickHTMLElement line:
ClickHTMLElement("A[HREF= 'http://www.chambre-portbail.fr/h']")
By
SavePictureAs("A[HREF= 'http://www.chambre-portbail.fr/h']","c:\test","outside")
- 66 -
8.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. Save the script uinder the name scriptweb14a. If the
Output window displays compilation errors, correct them and Run again.
9.
Open manually the c:\test folder to check that the image has been correctly
saved.
10.
The script can now be modified to call a Sub using three parameteres, the
HTML descriptor of the image to download, the name of the folder where to
save the image, the name of the file under which the image has to be saved.
11.
The Sub looks like:
Sub download_image(descriptor$, folder$, file$)
UsePage("Photos")
SavePictureAs(descriptor$, folder$, file$)
EndSub
12.
Modify the script by including at the begining of the script the lines for the Sub
and then in the middle of the script change the SavePictureAs lines by a call to
the Sub.
13.
In the WinTask Editor window, select the File/Save As menu option. In the
Save as dialog box, save the current script under the name scriptweb14b.
14.
Click the Play button
on the WinTask Toolbar to replay the actions
listed in the script. Add a second call to the Sub with the correct parameters
for saving the third photo.
Functions are similar to Subroutines with the exception that Functions return a result
to the calling script statement:
Function...EndFunction
The syntax for the Function, ExitFunction and EndFunction statements is as
follows:
- 67 -
Function <function_name>([<param1>[, <param2>] ...])
<statements>
<function_name> = <value>
ExitFunction
<statements>
EndFunction
A Function consists of a block of script statements surrounded by the Function and
EndFunction statements and the assignment of a return value to the Function’s
name. The name of the Function is specified by <function_name> and should be both
descriptive and unique. By default a Function returns an integer value. A Function
can return a string by appending the $ character to the end of the Function name.
The ExitFunction statement is typically used in conjunction with a conditional
statement to leave the Function before reaching the EndFunction statement. If the
script developer decides to use the ExitFunction statement, an assignment to
<function_name> must precede the ExitFunction statement. Functions can also
accept optional parameters, as designated by <param1>, which the Function can
perform operations on. The name of each parameter is a valid variable until the
EndFunction statement. Strings passed to the Function should end with the $
character.
TIP: Make sure the parameter names are different from any variables used
elsewhere in the script.
Since variables are global in scope, defining a
parameter with the same name as a variable can lead to confusion as to which
one (variable or parameter) is being referenced in the Function.
TIP: Make sure the Function appears in the script file before attempting to invoke it.
TIP: Failure to set the Function name equal to a value returns 0 to the calling script
statement. An empty string is returned if the Function returns a string but a
value was not assigned to the Function name.
- 68 -
An example of a Function and its invocation follows:
Function Absolute_diff(Integer1, Integer2)
If (Integer1 = Integer2) Then
Absolute_diff = 0
ExitFunction
Endif
If (Integer1 > Integer2) Then
Absolute_diff = integer1 - integer2
Else
Absolute_diff = Integer2 - Integer1
Endif
EndFunction
‘ Main Program
TestValue = 89
Result = Absolute_diff(TestValue, 123)
- 69 -
- 70 -
D a ta C a p t u re S c r i p t o n a " re a l " We b s i t e
In this chapter, the information presented in this document is put all together to
create a full Data Capture Script on a real web site. The techniques used in this
chapter can be used for capturing any data on a Web site where the data are on
multiple pages.
Before writing the script using your browser, you need to familiarize with the Web site
and understand what are the data to capture. So manually load in your browser this
Web url:
http://www.donaldson.com/en/index.html and click Part Search/Cross Reference
link.
The Cross Reference Search page loads and in Item # first field, type 145* and click
Search button. The next page displays a first table of results. The five columns of the
table will be captured. Then by clicking Next page link, the next data are displayed.
The script has to capture the five columns of the table for each results page, the last
page is seen as the last because the Next Page button does not exist on this page.
The script writes the captured data into an Excel file, which has five columns.
You must then think about the script structure: five arrays are needed to capture the
five columns, so five Dim lines will be at the very beginning of the script. The main
part launches the url and submits the request (clicking the first link, typing 145* and
clicking Search button). This 145* value could be too a variable, so the script could
work for any value to search. Two steps then are repetitive : the capture of the data
displayed on one page and the write to Excel.
As the creation of this script is a bit long, the code added at each step will be written
in italics. Appendix C contains the solution for this exercise, the script at its last stage
ready for execution.
Exercise 15 : Full Data Capture Script
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If Your First Script Wizard screen comes up, click Cancel
button. Click the New button on the WinTask Toolbar or select menu item
File/New if Untitled1 is not displayed.
- 71 -
2.
Click the Record button to start Recording Mode. When the Starting
Recording Mode dialog box appears, check Internet Explorer checkbox or
Mozilla Firefox or Google Chrome checkbox and click the OK button.
3.
The Launching Internet Explorer (or Launching Mozilla Firefox or
Launching
Google
Chrome)
dialog
box
will
appear.
Enter
http://www.donaldson.com/en/index.html into the Web address field
and click the OK button. The Donaldson Company main page is displayed,
click the Part Search/Cross Reference link.
4.
The page titled eCatalog – Cross Reference Search is displayed. Type
145* in the Item# second field and click the Search button.
5.
Stop Recording mode, the script looks like (change IE to FF or CH if you use
Firefox or Chrome):
StartBrowser("IE", "http://www.donaldson.com/en/index.html")
UsePage("Donaldson Company, Inc. - Americas Region - English")
ClickHTMLElement("A[INNERTEXT= 'Part Search/Cross Re']")
UsePage ("eCatalog - Cross Reference Search")
WriteHTML("INPUT TEXT[NAME= 'part_1']", "145*")
ClickHTMLElement("INPUT SUBMIT[VALUE= 'Search']")
6.
In the WinTask main window, select File/Save as.
box, save the script under the name scriptweb15.
In the Save as dialog
7.
Verify that the text cursor in the Editor window is after the last line of code
and start again the Recording mode by selecting Start/Recording menu
option. In the floating WinTask toolbar, click the Capture
mode is suspended.
- 72 -
icon. Recording
8.
Click Spy button in the Capture wizard screen.
9.
Move the mouse cursor on the table to capture: place it on the label of the
first column of the table (Search term), you see a black line surrounding a
rectangle around the table. Click the left mouse button, the captured data are
now displayed in the Capture Wizard screen.
- 73 -
10.
Click Next button. On the Specify the HTML element where the data to
be captured are dialog box, just click the Next button. The Select the data
you want to capture dialog box is displayed.
- 74 -
11.
As the capture must be done for each page and the label of the columns do
not have to be captured for each page, select columns C2 to C6 but without
selecting the R1 line.
- 75 -
12.
Click Next button. The Specify where to copy the captured data is
displayed. As the default is to copy them into Excel, just click Next button.
- 76 -
x
13.
The Specify the Excel file where to copy the extracted data dialog box is
displayed. In the Excel file field, type an Excel filename, for example
reference.xlsx. The file will be created in the folder where the script is
saved.
Or
write
the
full
path,
for
example,
c:\program
files\wintask\scripts\reference.xlsx (if the Excel file does not exist, it is
automatically created). As the first line of the Excel file will contain the column
headers, type A2 in the Cell starting at field to write the data starting at
column A and line 2.
- 77 -
14.
Click Paste into the script button.
15.
Recording mode resumes. Click the Next page link if there is one on the Web
page. Stop Recording mode by clicking the first icon of the WinTask floating
toolbar.
16.
Recording mode has generated all those lines:
- 78 -
Dim
Dim
Dim
Dim
Dim
tabcell_4$(100)
tabcell_3$(100)
tabcell_2$(100)
tabcell_1$(100)
tabcell_0$(100)
StartBrowser("IE","http://www.donaldson.com/en/index.html")
UsePage("Donaldson Company, Inc. - Americas Region - English")
ClickHTMLElement("A[INNERTEXT= 'Part Search/Cross Re']")
UsePage("eCatalog - Cross Reference Search")
WriteHTML("INPUT TEXT [NAME= 'part_1']", "145*")
ClickHTMLElement("INPUT SUBMIT[VALUE= 'Search']")
UsePage("eCatalog - Cross Reference Search")
ret = CaptureTableHTML("TABLE[CONTENT='Search Term']", "R2C2:R11C2",
tabcell_0$())
ret = WriteExcel("reference.xlsx", "Sheet1!A2:A11", tabcell_0$())
UsePage("Donaldson eCatalog - Cross Reference Search ")
ret = CaptureTableHTML("TABLE[CONTENT='Search Term']", "R2C3:R11C3",
tabcell_1$())
ret = WriteExcel("reference.xlsx", "Sheet1!B2:B11", tabcell_1$())
UsePage("eCatalog - Cross Reference Search ")
ret = CaptureTableHTML("TABLE[CONTENT='Search Term']", "R2C4:R11C4",
tabcell_2$())
ret = WriteExcel("reference.xlsx", "Sheet1!C2:C11", tabcell_2$())
UsePage("Donaldson eCatalog - Cross Reference Search ")
ret = CaptureTableHTML("TABLE[CONTENT='Search Term']", "R2C5:R11C5",
tabcell_3$())
ret = WriteExcel("reference.xlsx", "Sheet1!D2:D11", tabcell_3$())
UsePage("Donaldson eCatalog - Cross Reference Search ")
ret = CaptureTableHTML("TABLE[CONTENT='Search Term']", "R2C6:R11C6",
tabcell_3$())
ret = WriteExcel("reference.xlsx", "Sheet1!E2:E11", tabcell_4$())
Five arrays have been declared at the beginning of the script where the data of each
column will be stored.
Then each column is captured(CaptureTableHTML line) and its content is written to the
corresponding column of the Excel file (WriteExcel line).
17.
Click Play icon in the WinTask toolbar. If the Output window displays
compilation errors, correct them and click Play again. Open the Excel file
reference.xlsx to check the capture.
- 79 -
18.
Dim
Dim
Dim
Dim
Dim
Simplify the script to delete the useless UsePage lines and make it more
readable by changing the tabcell_x$ array names by more meaningful names.
searchterm$(100)
description$ (100)
mfrname$ (100)
mfritem$ (100)
dciitem$ (100)
19.
Check that the changes are correct : click the Play icon in the WinTask
toolbar. If the Output window displays compilation errors, correct them and
click Play again. Open the Excel file reference.xlsx to check the capture.
20.
As the script must repeat the capture and the writing a couple of times,
convert the Capture part in a Sub called capture_one_page and the Write part
in another Sub called write_result. Use a variable for the Excel file, for
example excelfile$.
- 80 -
Dim
Dim
Dim
Dim
Dim
searchterm$ (100)
description$ (100)
mfrname$ (100)
mfritem$ (100)
dciitem$ (100)
Function capture_one_page()
UsePage("eCatalog - Cross Reference Search ")
CaptureTableHTML("TABLE[CONTENT='Search Term']",
searchterm$())
CaptureTableHTML("TABLE[CONTENT='Search Term']",
mfritem$())
CaptureTableHTML("TABLE[CONTENT='Search Term']",
mfrname$())
CaptureTableHTML("TABLE[CONTENT='Search Term']",
CaptureTableHTML("TABLE[CONTENT='Search Term']",
description$())
EndFunction
"R2C2:R11C2",
"R2C3:R11C3",
"R2C4:R11C4",
"R2C5:R11C5", dciitem$())
"R2C6:R11C6",
Function write_result()
WriteExcel(excelfile$, "A2:A11", searchterm$())
WriteExcel(excelfile$,"B2:B11", mfritem$())
WriteExcel(excelfile$,"C2:C11", mfrname$())
WriteExcel(excelfile$,"D2:D11", dciitem$())
WriteExcel(excelfile$,"E2:E11",description$())
EndFunction
excelfile$="C:\Program Files (x86)\WinTask\Scripts\reference.xlsx"
StartBrowser("IE","http://www.donaldson.com/en/index.html")
UsePage("Donaldson Company, Inc. - Americas Region - English")
ClickHTMLElement("A[INNERTEXT= 'Part Search/Cross Re']")
UsePage("eCatalog - Cross Reference Search")
WriteHTML("INPUT TEXT [NAME= 'part_1']", "145*")
ClickHTMLElement("INPUT SUBMIT[VALUE= 'Search']")
capture_one_page()
write_result()
21.
As usual, check that the changes are working : click the Play icon in the
WinTask toolbar. If the Output window displays compilation errors, correct
them and click Play again. Open the Excel file reference.xlsx to check the
capture.
22.
If there are multiple pages for displaying the results, you have now to add the
loop for capturing the data on all the pages. The condition to exit the loop is
that the Next page button is not anymore displayed on the current page.
- 81 -
Testing if this button is there or not is made by the use of the
ExistHTMLElement function. If ExistHTMLElement("INPUT SUBMIT[VALUE=
'Next page']") equals 1, the button exists on the page. So include in the script
the loop repeat…until with the exiting condition. As the script must click the
Next page button if the button exists, a good programming technique is to use
a variable for example called exit with its default value to 0 and is assigned to
1 when the exiting condition is met. Like that you avoid the use of the Goto
function and have an easily readable script. Here is the code:
exit=0
repeat
capture_one_page()
write_result()
If existhtmlelement("INPUT SUBMIT[VALUE= 'Next page']") = 1 then
ClickHTMLElement("INPUT SUBMIT[VALUE= 'Next page']")
Else
Exit=1
EndIf
until exit = 1
23.
As usual, check that the changes are working : click the Play icon in the
WinTask toolbar. If the Output window displays compilation errors, correct
them and click Play again. Open the Excel file reference.xlsx to check the
capture. You see that the Excel file is incorrect.
24.
At each iteration, in the write_result Sub, the WriteExcel lines always write the
data from the line 2 to the line 21, and so delete the previously captured data
for the previous page. The start line where to write the new captured data has
to be stored. Modify the write_result Sub to use a new variable line_number.
Appendix C gives the solution.
At this point you should be able to use Recording mode to create a template script and
enhance it using WinTask language to automate a complex process.
- 82 -
Debugging
Compilation errors
When you run a script (SRC file), it is first compiled. In case of compilation errors,
those are listed in the Output window of the Editor (if the Output window is not
displayed, select menu item View/Output window to display it).
Double clicking an error line puts the cursor in the main window of the Editor on the
line which is in error for an easy correction.
Remember the order of statements within a script:
Dim statements first,
Sub and Functions second, and a call to a function within another one needs the
declaration of the called function before,
Main program last.
Included scripts must respect this structure.
Include statement: Include "tools.src"
Execution errors
Trace using MsgBox or MsgFrame
Exercise 16 : Trace script execution using MsgBox or MsgFrame
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If WinTask opens a previously saved script, close the window.
2.
Click the Open button
scriptweb10a.src script.
3.
From WinTask, select menu item File/Save As. Enter the name script16
when the Save As dialog is displayed. This step prepares for this exercise by
changing the script name and keeps the script10a.src available as a
reference.
on
the
WinTask
toolbar
and
open
Let’s suppose now that we have trouble with which value has i index. Insert in the
- 83 -
the
script first a Msgbox function for displaying i index for each iteration. Play. Then
change Msgbox function by a MsgFrame function (see MsgFrame help). Play.
TIP:
Note that Msgbox displays the value and prompts for an OK while
MsgFrame just displays the value. So Msgbox takes the focus and stops
script execution.
Log File
It is possible to request that each line during execution is logged in a log file. This
option is in menu item Configure/Run:
Full log generates a log file that each script line logged. Limited log writes in the log
only the Comment function lines encountered within the script.
Exercise 17 : Trace execution using a log file
1.
Launch the WinTask Editor. If the scriptweb16.src is not displayed in the
Editor window, click the Open icon on WinTask toolbar and open the
scriptweb16.src file.
2.
Configure the execution to generate a full log file (select Configure/Run
menu option) and launch the execution (click the Play icon on the WinTask
toolbar).
3.
Open the log file (select the File/Open Log menu option) – see the different
lines in this full log file. Close the log file.
4.
In the Editor window, replace the msgbox or msgframe line by this line
Comment ("Index i equals:"+str$(i)).
5.
Save the modified script under the name scriptweb17a (File/Save as menu
option).
- 84 -
6.
Configure the execution to generate a limited log file (Configure/Run menu
option).
7.
Click Play icon in the WinTask toolbar. If the Output window displays
compilation errors, correct them and click Play again.
8.
Open the log file (select the File/Open Log menu option) – see the different
lines in this limited log file. Close the log file.
9.
In the Editor window, select again the Configure/Run menu option and
uncheck the Log checkbox and click the OK button. Next executions will not
anymore generate log files.
Creation of your own log procedure:
You can write yourself your own log Sub; here is an example:
sub log(msg_log$)
local buffer$
buffer$=Date$()+", "+hour$()+":"+min$()+":"+sec$()+" --> "+msg_log$
write(file_log$,buffer$,CRLF)
endsub
Using the script done in exercise 17, integrate this Sub in the script, and replace the
COMMENT line by a call to this proc. Add a line to assign the log_file$ variable to a file
with a txt extension. Save the script as scriptweb17b and Play. Open the txt file
which has been generated.
Timeout error message on a page loading
If this error message pops up when a StartBrowser line runs, two possible reasons:
The Web page takes more time than the default value to load (the default maximum
time allowed to a page to load is 30 seconds). You can change this timeout by
inserting above the StartBrowser line the line #ActionTimeout=60 (the timeout
becomes then 60 seconds). If the other pages of the Web site load faster, you can
come back to the default timeout value by inserting the line #ActionTimeout=30 just
after the StartBrowser line.
StartBrowser includes an automatic synchronization and the next line in the script can
be run only if the url has finished to load. If a Security Alert window or a Credentials
window pops up, such a window prevents the url to load before you exit the window.
To avoid this behavior, use the Shell function instead of the StartBrowser function.
Such a Shell line can be generated automatically by starting Recording mode, and in
the "What do you want to start before recording" dialog box, you leave checked An
application and click OK button, and in the next dialog box, in the Program field,
you click Browse button to look for IEXPLORE.EXE (the exe for Internet Explorer) and
- 85 -
in the Parameters field, you type the url you want to launch.
If this error message pops up when a UsePage is executed, do not close manually the
page in error and compare the its title to the title which is in the UsePage line. Ajust
the title to reflect the correct page title.
Another reason can be that the page has not finished loading within the 30 seconds
timeout value which is the default. Use then #ActionTimeout to specify a longer
timeout.
Another possible reason is that at replay, the page which should have loaded did not
due to the previous action not replayed correctly. See ClickHTMLElement does not
return an error but does not click paragraph below.
ClickHTMLElement does not return an error but does not click
That's a "visual" error : at replay, you see the mouse clicking somewhere but it's not
at the place it should. Then the next UsePage fails as the click has not be done
correctly.
Three possible reasons:
The click is done but not precisely on the small link. Use the optional parameters of
ClickHTMLElement to force the click at the correct place:
ClickHTMLElement("A[INNERTEXT= ' Free Downloads']", left, 5, 5)
Clicks the HTML object named Free Downloads but with a small shift of 5 pixels to
the left and up.
The click is done at totally a different place as expected. That means that the HTML
descriptor used in the ClickHTMLElement refers to an object which is not the
expected one. Modify the HTML descriptor using Spy tool and the Change Proposed
CONTENT button.
The HTML object position is not fully stable even when the page has finished
loading. To force an additional synchronization, use the #HTMLPosRetry system
variable. See the Incorrect form filling paragraph below.
Navigate, a workaround
The Navigate function can replace a ClickHTMLElement on a link. Ar replay, Navigate
goes directly to the specified url and includes an automatic synchronization.
For example, on www.wintask.com, if you record a click on Buy Now link, it
generates the line:
ClickHTMLElement("A[INNERTEXT= 'Buy Now']")
- 86 -
And this click opens the page titled Buy Wintask.
You can replace the ClickHTMLElement line by a direct navigation to the page Buy
Wintask:
Navigate("http://www.wintask.com/buy-wintask.php")
Incorrect Form Filling
No error is reported when executing a WriteHTML line, but you see that the fiel dis not
correctly filled. This happens when the HTML object position is not yet stable even
when the page has finished loading.
To force an additional synchronization for this specific object, use the #HTMLPosRetry
system variable. With this variable at a value different from its default value at 0, the
position of the object is verified once or several times before writing into it.
HTML object not found
Those errors happen when replaying actions on a page already loaded.
Two possible reasons to not find an HTML object when replaying a line which uses an
HTML descriptor as parameter (ClickHTMLElement, WriteHTML, CaptureHTML,
CaptureTableHTML, GetHTMLEditText, OverHTMLElement,… ) : it can be a
synchronization problem, the object to use is not yet displayed on the page – or the
specified object uses an HTML descriptor which is not the same as the one it has when
you recorded the action (the HTML descriptor has changed). To understand where the
error comes from and correct, follow those steps:
1.
Play the script.
2.
When the execution stops and an error message is displayed, click the OK
button in the error dialog box but do not close the Internet Explorer window.
3.
If you can see that the page is not fully loaded, the HTML object has not beed
found due to a synchronization problem. Correct using the tips given above at
Timeout error message paragraph.
4.
If the Web page is the correct one and is fully loaded, the HTML descriptor is
perhaps not the correct one. Restore the WinTask Editor window and create a
new script.
5.
Start Recording mode. On the "What do you want to start before recording"
dialog box, check the Nothing button and click the OK button.
- 87 -
6.
On the Web page where the HTML object is displayed, click the object which
creates the error.
7.
Stop Recording mode, a small script has been generated with jsut the step
where the problem occurs. Manually come back to the page where the small
script must find the object.
8.
Play the small script, give a name when prompted and you see the action
replayed.
9.
If the small script replays without any error, compare the HTML descriptor as
it is in the small script and the one in the script where the execution error
occurs. If they are different, modify in the script in error. If they are the
same, include in the script in error an additional synchronization to wait until
the HTML object to use is displayed.
A Table capture does not return the expected data
The Capture functions use the content of the HTML object to capture to identify the
data to capture. It is the CONTENT keyword : for example, the capture of a text
displayed in a paragraph has this syntax if the first word of the paragraph is 2014:
CaptureHTML("P[CONTENT='2014']",captured_text$)
So the HTML descriptor for paragraphs or tables rely on the first word of the
paragraph or the table. But sometimes, this word is not enough to identify uniquely
the HTML object or this word varies on the displayed page.
The following exercise demonstrates how to modify the CONTENT keyword content to
be sure that the script at replay captures the correct data. Appendix C contains the
solution for this exercise.
Exercise 18 : CONTENT keyword change for a correct capture
1.
Launch the WinTask Editor.
The title bar should display WinTask –
[Untitled1]. If WinTask opens a previously saved script, close the script and
click New icon on WinTask toolbar.
2.
Click the Record button to start Recording Mode. When the Starting
Recording Mode dialog box appears, check Internet Explorer checkbox or
Mozilla Firefox checkbox or Google Chrome checkbox, and click the OK
button. In the Web address field, type www.wintask.com/demos/pagenews.htm and click the OK button.
3.
The page titled News Page will display. This page simulates a News page
with different paragraphs and the text of the news varies along the day. The
script must capture the different news which are displayed.
- 88 -
4.
Click the Capture button
on the WinTask Floating Toolbar to call the
Capture Wizard. Recording mode is suspended.
5.
Click Spy button. The mouse cursor changes its shape.
6.
Move the mouse cursor on the table to capture, starting at 12/05/2014. A
black rectangle surrounds the text of the paragraph when the mouse cursor is
above it. Click once, the captured data are displayed in the Capture Wizard
dialog box.
- 89 -
7.
Click Next button. The Specify the HTML element where the data to be
captured are is displayed and shows an HTML descriptor using the first word
of the paragraph to capture, "TABLE[CONTENT='12']".
- 90 -
8.
The descriptor using the CONTENT keyword uses the 13 value, day for the
news to capture. The content will be incorrect the next day, so you need to
change the descriptor. Click the Change proposed content button.
- 91 -
9.
You must choose in the captured text a string of characters which does not
change when the news change. One word which does not change except
every year is the year string. So use this word for the CONTENT keyword :
using the mouse, copy 2014 from the Captured text field and paste it in the
Change proposed content field. The Validate button becomes active.
- 92 -
10.
Click the Validate button to verify that the selected CONTENT is correct t o
identify uniquely the paragraph to capture. The Descriptor field contains now
the new descriptor.
11.
Click the OK button. You come back to the "Specify the HTML element where
the data to be captured are" and the HTML descriptor field reflects the
change made in the previous step.
- 93 -
12.
Click the Next button, the next dialog box displays the captured data, click
Next button to take the 2 columns. In Specify where to copy the captured
data dialog box, check Array checkbox and click Next button. Finally on the
next dialog box, click the Paste into the script button.
13.
Stop Recording mode, the Editor window comes back to focus and you can
see the lines generated by the Capture Wizard :
UsePage("News Page")
ret = CaptureTableHTML("TABLE[CONTENT='2014']", "R1C1:R3C1", tabcell_0$()
ret = CaptureTableHTML("TABLE[CONTENT='2014']", "R1C2:R3C2", tabcell_1$()
- 94 -
The first UsePage line waits until the page is fully loaded before starting the
capture. The next two line capture the text of the two columns of the news table
and store it in two arrays. Replace the array names by dateday$ and textnews$
for more meaningful names.
14.
Close the Internet Explorer window.
15.
Stop Recording mode.
16.
Add at the end of the script two msgbox lines for displaying the content of the
first value of the two arrays.
17.
Click the Play icon on the WinTask Editor window. Save the script under the
name scriptweb18. The captured values are displayed in two successive
dialog boxes.
TIP:
ret
Year 2014 is used in CONTENT, so the script will not work anymore in
2015! You can use the Year$ function to find automatically the current
year. The CaptureHTML line becomes:
=
CaptureTableHTML("TABLE[CONTENT='"+Year$()+"']",
dateday$()
"R1C1:R3C1",
Internet Explorer Menu Option not selected
At replay, a ChooseMenu line for selecting a menu option does not select the specified
option. This can happen on context menu options.
You can use instead the keyboard shortcuts:
For example in notepad, the File/Save menu can be automatized using:
UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad")
SendKeys("<Alt f>",Noactivate)
pause 5 ticks
SendKeys("s",NoActivate)
Note the small Pause line between the selection of the Alt+f keyboard shorcut and the
s for Save : it gives a small time to the menu File to open.
Option in a menu of a Web page not selected
- 95 -
More and more Web pages include "over" menus : the options below a main menu
option are displayed only when the mouse is above the main menu option.
The OverHTMLElement WinTask function automatizes this mouse over the option.
To record such a mouse over, press once the Shift key and click the main menu option
for the menu you want to expand. Here is an example where the Company main menu
expands its menu of options, and Contact us option is then clicked
OverHTMLElement("DIV[OUTERTEXT= 'Company']")
ClickHTMLElement("DIV[OUTERTEXT= 'Contact Us']")
The Recording mode can generate several OverHTMLElement identical lines if you
press Shift key for a while. Delete manually all the generated lines to keep only one.
Context menu selection does not replay
WinTask includes SaveTargetAs and SavePictureAs functions which have to be used
isntead of Save Target as and Save image as context menu options. Exercise 14
showed how to use SavePictureAs. The SaveTargetAs function is used the same way.
Low level Recording mode when nothing works
With this other way to record, the actions are recorded as mouse clicks not any more
as objects.
Use only for a short time just when needed
Configure by selecting menu item Configure/Recording.
- 96 -
Example, menu File/Open recorded in normal way versus recording in Low level:
Shell("notepad",1)
UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
ChooseMenu(Normal,"&File|&Open... Ctrl+O")
UseWindow("NOTEPAD.EXE|#32770|Open",1)
Click(Button,"Cancel")
CloseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
In Low level:
Shell("notepad",1)
UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
ClickMouse(Left,Down,30,51)
ClickMouse(Left,Up,30,51)
ClickMouse(Left,Down,22,93)
ClickMouse(Left,Up,22,93)
UseWindow("NOTEPAD.EXE|Button|Cancel",1, NoActivate)
ClickMouse(Left,Down,72,19)
ClickMouse(Left,Up,72,19)
UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
ClickMouse(Left,Down,530,16)
ClickMouse(Left,Up,530,16)
- 97 -
Slow execution
A script written for Internet Explorer 6 replays slower when run with newer versions of
Internet Explorer. It is because the Internet Explorer window names are not the same
for those two versions of Internet Explorer.
For example, to close the Internet Explorer window for a WinTask Web page, the line
under IE6 is:
CloseWindow("IEXPLORE.EXE|IEFrame|WinTask - Microsoft Internet Explorer",1)
Under IE7/8/9/10/11, the line is:
CloseWindow("IEXPLORE.EXE|IEFrame|WinTask – Windows Internet Explorer",1)
At replay, WinTask looks first for a window with the exact same window name and
after 3 secs (default value related to #ActionTimeout system variable) starts to
truncate the window name by its rightmost part.
If you truncate manually the window name to accept any IE name, such as:
"IEXPLORE.EXE|IEFrame|WinTask”, the window will be immediately found:
CloseWindow("IEXPLORE.EXE|IEFrame|WinTask",1)
You can apply the same technique if a UseWindow line replays slowly.
Two other system variables can be used for speeding up execution:
#HTMLPosRetry
#ExecuteDelay
See help on those variables.
Capture Wizard cannot capture the desired data
If for whatever reason, the Capture Wizard cannot suit your capture need, you can
still use the GetPageSource$ function to retrieve all the source of the HTML page, and
then using the ExtractBetween$ function, you extract only the part you are interested
in.
If the page contains frames, you can use the GetFramesource$ function.
- 98 -
Conclusion
With those few examples, you were able to see the extraordinary flexibility of WinTask
to automatize any task on Web sites.
We showed too the usual tips to create scripts replaying reliably. Keep in mind that
the script must be independant of the environment which can change from one
execution to another (the file exists or not, the current folder has changed, …
This book did not address the specific WinTask functions for pure Windows
applications. You can download the book for Windows automation from our web site
http://www.wintask.com/wintaskbook.pdf
Feel free to post your remarks on this book at [email protected].
- 99 -
- 100 -
APPENDIX A
WinTask Toolbar
The WinTask Toolbar offers the following functionality. The toolbar and button images
present the large buttons.
New Script Window. Open a new automation script window.
Open Script File. Open an existing automation script file and load into a
new window.
Save Script File. Save the contents of the active automation script window
to a file.
Start Spy Tool. Launch the Spy tool.
Start Capture Tool. Launch the Capture tool.
Start Recording Mode. Record the user’s keyboard, menu, and mouse
actions and record them in the active automation script window.
Compile and Execute. Compile the automation script in the active window
and replay.
Text Synchronization. Invokes the Text Synchronization wizard.
the generated script into the active automation script window.
Insert
OCR Text Synchronization. Invokes the OCR Text Synchronization
wizard.
Insert the generated script into the active automation script
window.
Image Synchronization. Invokes the Image Synchronization wizard.
Insert the generated script into the active automation script window.
Window Synchronization. Invokes the Window Synchronization wizard.
Insert the generated script into the active automation script window.
- 101 -
Date/Hour Synchronization. Invokes the Date/Hour Synchronization
wizard.
Insert the generated script into the active automation script
window.
Keyboard Synchronization. Invokes the Wait for Keyboard Action
Synchronization wizard.
Insert the generated script into the active
automation script window.
Menu Synchronization. Invokes the Wait for Menu Action Synchronization
wizard.
Insert the generated script into the active automation script
window.
Mouse Synchronization. Invokes the Wait for Mouse Click Action
Synchronization wizard.
Insert the generated script into the active
automation script window.
Language List. Open the Insert Language dialog to insert WinTask Script
Language statements into the active automation script window.
Start Scheduler Tool.
Launch the Scheduler tool to execute an
automation script at a specified time (Scheduler is not available under Vista,
Windows 7 and Windows 2008).
- 102 -
APPENDIX B
WinTask Floating Toolbar
During Recording Mode, WinTask converts itself into a floating toolbar. The toolbar
offers the following functionality while in Recording Mode:
Stop Recording Mode. Restores the WinTask Editor.
Start Spy Tool. Launches the Spy tool.
Start Capture Wizard.
Invokes the Capture wizard. Insert the
generated lines into the automation script being recorded.
Text Synchronization.
Invokes the Text Synchronization wizard.
Insert the generated lines into the automation script being recorded.
OCR Text Synchronization. Invokes the OCT Text Synchronization
wizard. Insert the generated lines into the automation script being
recorded.
Image Synchronization. Invokes the Image Synchronization wizard.
Insert the generated lines into the automation script being recorded.
Window Synchronization.
Invokes the Window Synchronization
wizard. Insert the generated lines into the automation script being
recorded.
Time Synchronization. Invokes the Time Synchronization wizard.
Insert the generated lines into the automation script being recorded.
Date/Hour Synchronization.
Invokes the Date and Time
Synchronization wizard. Insert the generated lines into the automation
script being recorded.
Keyboard Synchronization. Invokes the Wait for Keyboard Action
Synchronization wizard. Insert the generated lines into the automation
script being recorded.
- 103 -
Menu Synchronization.
Invokes the Wait for Menu Action
Synchronization wizard. Insert the generated lines into the automation
script being recorded.
Mouse Synchronization. Invokes the Wait for Mouse Click Action
Synchronization wizard. Insert the generated lines into the automation
script being recorded.
Insert Lines. Opens the Insert Lines in to Script dialog in which the
user can insert lines directly into the automation script being recorded.
- 104 -
APPENDIX C
Exercises Solutions
The solutions to the programming exercises are provided below.
They have been developed using WinTask x64 under Windows 7 64 bits and Internet
Explorer 11 or Firefox .
Exercise 4, Scriptweb04.src
'================================================================
' Scriptweb04
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 4
'
' The UsePage functions have been added manually to force the wait until the new page is loaded
‘ even when all the pages have the same title.
'================================================================
StartBrowser("FF", "www.wintask.com/demos/identicalpage1.htm")
UsePage("Page Title")
ClickHTMLElement ("A[INNERTEXT= 'here']")
' UsePage added there : the script waits until the page Page Title is fully loaded.
UsePage("Page Title")
ClickHTMLElement("A[INNERTEXT= 'previous page']")
' UsePage added there : the script waits until the page Page Title is fully loaded.
UsePage("Page title")
WriteHTML("INPUT TEXT[NAME= 'name']", "My name")
CloseWindow("FIREFOX.EXE|MozillaWindowClass|Page Title - Mozilla Firefox",1)
- 105 -
Exercise 5, Scriptweb05.src
'================================================================
' Scriptweb05
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Text synchronization demonstrated on notepad.
'================================================================
Shell("C:\Windows\System32\notepad.exe")
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
SendKeys("Hello WinTask<Enter>")
SendKeys("<Enter>")
SendKeys("The weather is warm today")
Pause 10 secs until
Text("is warm")
InWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
PauseFalse
MsgBox("The text is warm has not been typed in notepad")
End
EndPause
msgbox("The text is now displayed ")
CloseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
UseWindow("NOTEPAD.EXE|CtrlNotifySink|Notepad|8",1)
Click(Button,"Do&n't Save")
.
- 106 -
Exercise 6, Scriptweb06.src
'================================================================
' Scriptweb06
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 6
'
' OCR Text synchronization needed when all the pages have the same title,
‘ and the page to wait for does not contain any HTML object to synchronize on.
'================================================================
StartBrowser("IE", "www.wintask.com/demos/identicalpage1.htm")
UsePage("Page Title ")
ClickHTMLElement("A[INNERTEXT= 'here']")
' If you use WinTask OCR engine, the next line is UseOCREngine(2)
Ret=UseOCREngine(1)
Pause 20 secs until
TextOCR("text")
InWindow("IEXPLORE.EXE|Internet Explorer_Server|Page Title - |1",1)
InArea(159,234,33,154)
PauseFalse
MsgBox("The page took more than 20 seconds to load!")
End
EndPause
msgbox("The text is now displayed")
ClickHTMLElement("A[INNERTEXT= 'previous page']")
CloseWindow("IEXPLORE.EXE|IEFrame|Page Title - Windows Internet Explorer",1)
- 107 -
Exercise 7 Scriptweb07.src
'================================================================
' Scriptweb07
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 7
'
' Window synchronization to wait until a File Download is complete. Applies only for
‘ Internet Explorer versions before version 9.
'================================================================
StartBrowser("IE", "www.wintask.com/demos")
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'File']")
' This line is added manually to delete the file which has already been saved
' during the Recording session.
Kill("c:\program files\wintask\scripts\test.test")
' The last number 2 in the line below is the instance number of the IEXPLORE.EXE window.
' To make the script independant of this instance, replace 2 by topinstance(), such as
'UseWindow("IEXPLORE.EXE|#32770|File Download – Security warning",topinstance())
UseWindow("IEXPLORE.EXE|#32770|File Download – Security warning",2)
Click(Button,"&Save")
UseWindow("IEXPLORE.EXE|FloatNotifySink|Save As|1",1)
WriteCombo("1","c:\program files\wintask\scripts\test.test")
UseWindow("IEXPLORE.EXE|#32770|Save as",1)
Click(Button,"&Save")
Pause 150 secs until
WinStatus(Exists,Exact)
InWindowAnyInstance("IEXPLORE.EXE|#32770|Download complete")
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
'See remark above for replacing the 2 by topinstance()
UseWindow("IEXPLORE.EXE|#32770|Download complete",2)
Click(Button,"Close")
'CloseBrowser function closes any Internet Explorer window.
CloseBrowser()
- 108 -
Exercise 8 Scriptweb08.src
'================================================================
' Scriptweb08
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Absolute Pause
'================================================================
StartBrowser("IE", "www.wintask.com/manuals.php")
UsePage("WinTask Manuals")
ClickHTMLElement("A[INNERTEXT= 'Tutorial']")
Pause 60 secs
'To simulate a Back button, prefer to use the PreviousPage() WinTask function which works for IE, FF or CH.
PreviousPage()
CloseWindow("IEXPLORE.EXE|IEFrame|WinTask",1)
- 109 -
Exercise 9, Scriptweb09a.src
'================================================================
' Scriptweb09a
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 9, part 1
'
' This script uses a variable to type a file name.
'================================================================
' This string variable is used lated in the script to type
' the name of the file in the Save as dialog box
filename$="c:\program files (x86)\wintask\scripts\test.test"
StartBrowser("IE","www.wintask.com/demos",3)
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'Page 2']")
UseWindow("IEXPLORE.EXE|CommandToolbarBand|Page 2 - Windows Internet Explorer|1",1)
ChooseItem(ToolBar, "Command Bar", "&Page", dropdown, left )
UseWindow("IEXPLORE.EXE|ToolbarWindow32|Command Bar",1)
ChooseMenu(Context,"|5")
' The filename$ variable filename$ replaces the name of the file in the WriteCombo function.
UseWindow("IEXPLORE.EXE|FloatNotifySink|Save Webpage|1",2)
WriteCombo("1",filename$)
UseWindow("IEXPLORE.EXE|#32770|Save Webpage",topinstance())
Click(Button,"&Save")
CloseBrowser()
- 110 -
Exercise 9, Scriptweb09b.src
'================================================================
' Scriptweb09b
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 9, part 2
'
' This script introduces a condition and used the ExistW function
' to test if a window exists and click in it only if the window is there.
'================================================================
' This string variable is used lated in the script to type
' the name of the file in the Save as dialog box
filename$="c:\program files (x86)\wintask\scripts\test.test"
StartBrowser("IE","www.wintask.com/demos",3)
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'Page 2']")
UseWindow("IEXPLORE.EXE|CommandToolbarBand|Page 2 - Windows Internet Explorer|1",1)
ChooseItem(ToolBar, "Command Bar", "&Page", dropdown, left )
UseWindow("IEXPLORE.EXE|ToolbarWindow32|Command Bar",1)
ChooseMenu(Context,"|5")
' The filename$ variable filename$ replaces the name of the file in the WriteCombo function.
UseWindow("IEXPLORE.EXE|FloatNotifySink|Save Webpage|1",2)
WriteCombo("1",filename$)
UseWindow("IEXPLORE.EXE|#32770|Save Webpage",topinstance())
Click(Button,"&Save")
' Test if the Save Webpage window asking if the file has to be replaced or not
' is displayed. Add a small Pause line to give time to the window to appear
Pause 1
If ExistW("IEXPLORE.EXE|#32770|Confirm Save As",topinstance()) = 1 then
UseWindow("IEXPLORE.EXE|CtrlNotifySink|Confirm Save As|7",topinstance())
Click(Button,"&Yes")
Endif
Pause 1
CloseBrowser()
- 111 -
Exercise 9, Scriptweb09c.src
'================================================================
' Scriptweb09c
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 9, part 3
'
' This script uses a condition based on the return code of a UseWindow function,
' to test if the Save as dialog box is there. #IgnoreErrors=1 is used to avoid
' that script execution stops if the window is not found by UseWindow.
'================================================================
' This string variable is used lated in the script to type
' the name of the file in the Save as dialog box
filename$="c:\program files (x86)\wintask\scripts\test.test"
StartBrowser("IE","www.wintask.com/demos",3)
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'Page 2']")
UseWindow("IEXPLORE.EXE|CommandToolbarBand|Page 2 - Windows Internet Explorer|1",1)
ChooseItem(ToolBar, "Command Bar", "&Page", dropdown, left )
UseWindow("IEXPLORE.EXE|ToolbarWindow32|Command Bar",1)
ChooseMenu(Context,"|5")
' The filename$ variable filename$ replaces the name of the file in the WriteCombo function.
UseWindow("IEXPLORE.EXE|FloatNotifySink|Save Webpage|1",2)
WriteCombo("1",filename$)
UseWindow("IEXPLORE.EXE|#32770|Save Webpage",topinstance())
Click(Button,"&Save")
' #IgnoreErrors is set up to 1, so if the window specified in the UseWindow function
'is not found, the script execution still goes on.
'Then the return code of UseWindow is tested in order to click the Yes button
'only if the window is found.
#IgnoreErrors = 1
Pause 1
Ret=UseWindow("IEXPLORE.EXE|#32770|Confirm Save As",topinstance())
If ret = 0 Then
Click(Button,"&Yes")
Endif
' Restore the default error management.
#IgnoreErrors = 0
CloseBrowser()
- 112 -
Exercise 9, Scriptweb09d.src
' '================================================================
' Scriptweb09d
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 9, part 4
'
' Same script as the one above but the name of the file is changed.
'================================================================
' This string variable is used lated in the script to type
' the name of the file in the Save as dialog box
filename$="c:\program files (x86)\wintask\scripts\demo09d.test"
StartBrowser("IE","www.wintask.com/demos",3)
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'Page 2']")
UseWindow("IEXPLORE.EXE|CommandToolbarBand|Page 2 - Windows Internet Explorer|1",1)
ChooseItem(ToolBar, "Command Bar", "&Page", dropdown, left )
UseWindow("IEXPLORE.EXE|ToolbarWindow32|Command Bar",1)
ChooseMenu(Context,"|5")
' The filename$ variable filename$ replaces the name of the file in the WriteCombo function.
UseWindow("IEXPLORE.EXE|FloatNotifySink|Save Webpage|1",2)
WriteCombo("1",filename$)
UseWindow("IEXPLORE.EXE|#32770|Save Webpage",topinstance())
Click(Button,"&Save")
' #IgnoreErrors is set up to 1, so if the window specified in the UseWindow function
'is not found, the script execution still goes on.
'Then the return code of UseWindow is tested in order to click the Yes button
'only if the window is found.
#IgnoreErrors = 1
Pause 1
Ret=UseWindow("IEXPLORE.EXE|#32770|Confirm Save As",topinstance())
If ret = 0 Then
Click(Button,"&Yes")
Endif
' Restore the default error management.
#IgnoreErrors = 0
CloseBrowser()
- 113 -
Exercise 10, Scriptweb10a.src
'================================================================
' Scriptweb10a
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 10, part 1
'
' This script uses a loop to click the n page numbers
' and load each of them.
'================================================================
StartBrowser("IE","www.wintask.com/demos/page-iteration1.htm",3)
i=2
While i <= 7
UsePage("Page Iteration 1")
' The string speciying the HTML descriptor for each page must follow this syntax:
' the string starts with A[INNERTEXT= '
text between " character as it is a string,
' then concatenate with str$(i), the index i which is an integer is converted to
' a string using str$ function
' The string ends with '] those two characters are surrounded again by " as it is a string.
ClickHTMLElement("A[INNERTEXT= '"+str$(i)+"']")
' The page title changes from one page to another, so again the concatenation is used.
UsePage("Page Iteration "+str$(i))
ClickHTMLElement("A[INNERTEXT= 'here']")
i=i+1
Wend
CloseBrowser()
- 114 -
Exercice 10, Scriptweb10b.src
'================================================================
' Scriptweb10b
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 10, part 2
'
' This script uses a loop to click the n page numbers
' and load each of them.
'================================================================
' As all the page titles start with the same characters WinTask – Page Itération,
' it's better to force #UsePageExact=1 to ensuire a correct synchronization by the UsePage function.
#UsePageExact = 1
StartBrowser("IE","www.wintask.com/demos/page-iteration1.htm",3)
i=2
repeat
' The string speciying the HTML descriptor for each page must follow this syntax:
' the string starts with A[INNERTEXT= '
text between " character as it is a string,
' then concatenate with str$(i), the index i which is an integer is converted to
' a string using str$ function
' The string ends with '] those two characters are surrounded again by " as it is a string.
ClickHTMLElement("A[INNERTEXT= '"+str$(i)+"']")
' The page title changes from one page to another, so again the concatenation is used.
UsePage("Page Iteration "+str$(i))
ClickHTMLElement("A[INNERTEXT= 'here']")
i=i+1
until i = 8
CloseBrowser()
- 115 -
Exercise 11, Scriptweb11.src
'================================================================
' Scriptweb11
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 11
'
' This script captures data displayed in a Table on a Web page.
'================================================================
Dim tabcell_2$(100)
Dim tabcell_1$(100)
Dim tabcell_0$(100)
StartBrowser("IE", "www.wintask.com/demos/data.htm",3)
UsePage("Capture Data from a Web Table ")
ret = CaptureTableHTML("TABLE[CONTENT='Name']", "R1C1:R6C1", tabcell_0$())
ret = WriteExcel("c:\program files (x86)\wintask\scripts\data.xlsx", "Sheet1!A1:A6", tabcell_0$())
ret = CaptureTableHTML("TABLE[CONTENT='Name']", "R1C2:R6C2", tabcell_1$())
ret = WriteExcel("c:\program files (x86)\wintask\scripts\data.xlsx", "Sheet1!B1:B6", tabcell_1$())
ret = CaptureTableHTML("TABLE[CONTENT='Name']", "R1C3:R6C3", tabcell_2$())
ret = WriteExcel("c:\program files (x86)\wintask\scripts\data.xlsx", "Sheet1!C1:C6", tabcell_2$())
CloseBrowser()
'================================================================
' The same script with meaningful names for the arrays
'================================================================
Dim phone$(100)
Dim email$(100)
Dim name$(100)
StartBrowser("IE", "www.wintask.com/demos/data.htm",3)
UsePage("Capture Data from a Web Table")
ret = CaptureTableHTML("TABLE[CONTENT='Name']", "R1C1:R6C1", name$())
ret = WriteExcel("c:\program files (x86)\wintask\scripts\data.xlsx", "Sheet1!A1:A6", name$())
ret = CaptureTableHTML("TABLE[CONTENT='Name']", "R1C2:R6C2", email$())
ret = WriteExcel("c:\program files (x86)\wintask\scripts\data.xlsx", "Sheet1!B1:B6", email$())
ret = CaptureTableHTML("TABLE[CONTENT='Name']", "R1C3:R6C3", phone$())
ret = WriteExcel("c:\program files (x86)\wintask\scripts\data.xlsx", "Sheet1!C1:C6", phone$())
CloseBrowser()
- 116 -
Exercise 12, Scriptweb12.src
'================================================================
' Scriptweb12
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 12
'
' This script types data in a Web form.
'================================================================
StartBrowser("IE","www.wintask.com/demos",3)
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'Form']")
UsePage("Form")
WriteHTML("INPUT TEXT[NAME= 'name']", "SMITH")
WriteHTML("INPUT TEXT [NAME= 'email']", "[email protected]")
WriteHTML("INPUT TEXT [NAME= 'phone']", "820123456")
ClickHTMLElement("INPUT RESET[VALUE= 'Clear'] ")
CloseBrowser()
- 117 -
Exercise 13, Scriptweb13a.src
'================================================================
' Scriptweb13a
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 13, part 1
'
' This script reads data from an Excel file and
' types them in a Web form using a loop.
'================================================================
Dim name$(10)
Dim email$(10)
Dim phone$(10)
filename$="c:\program files (x86)\wintask\scripts\data.xlsx"
ReadExcel(filename$,"A2:A6",name$())
ReadExcel(filename$,"B2:B6",email$())
ReadExcel(filename$,"C2:C6",phone$())
StartBrowser("IE","www.wintask.com/demos",3)
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'Form']")
i=0
While i < 5
UsePage("Form")
WriteHTML("INPUT TEXT[NAME= 'name']", name$(i))
WriteHTML("INPUT TEXT[NAME= 'email']", email$(i))
WriteHTML("INPUT TEXT[NAME= 'phone']", phone$(i))
ClickHTMLElement("INPUT RESET[VALUE= 'Clear']")
i= i + 1
Wend
CloseBrowser()
'================================================================
' Scriptweb13b
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 13, part 2
'
' This script reads data from an Excel file and
' types them in a Web form using a loop until there is no more data in the Excel file.
'================================================================
' To be able to process a maximum of 100 data for each column, the size of the arrays is increased
Dim name$(100)
Dim email$(100)
Dim phone$(100)
filename$="c:\program files (x86)\wintask\scripts\data.xlsx"
ReadExcel(filename$,"A2:A100",name$())
ReadExcel(filename$,"B2:B100",email$())
- 118 -
ReadExcel(filename$,"C2:C100",phone$())
StartBrowser("IE","www.wintask.com/demos",3)
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'Form']")
i=0
' While name$(i) is not empty, the loop goes on.
While name$(i) <> ""
UsePage("Form")
WriteHTML("INPUT TEXT[NAME= 'name']", name$(i))
WriteHTML("INPUT TEXT[NAME= 'email']", email$(i))
WriteHTML("INPUT TEXT[NAME= 'phone']", phone$(i))
ClickHTMLElement("INPUT RESET[VALUE= 'Clear']")
i= i + 1
Wend
CloseBrowser()
- 119 -
Exercise 14, Scriptweb14a.src
'================================================================
' Scriptweb14a
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 14, part 1
'
' This script downloads images from a Web site and
' saves them on hard disk.
'================================================================
StartBrowser("IE", "www.chambre-portbail.fr",3)
UsePage("Chambre d'hôtes entre Lessay et Portbail - La Varecherie")
ClickHTMLElement("A[INNERTEXT= 'Galerie Photos']")
UsePage("Photos - La Varecherie")
'The HTML descriptor generated automatically is used as first parameter of SavePictureAs
SavePictureAs("A[HREF= 'http://www.chambre-portbail.fr/h']","c:\test","outside")
CloseBrowser()
'================================================================
' Scriptweb14b
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 14, part 2
'
' The actions for downloading the images are put into a Sub.
'================================================================
Sub download_image(descriptor$,folder$, file$)
UsePage("Photos - La Varecherie")
SavePictureAs(descriptor$,folder$,file$)
EndSub
StartBrowser("IE", "www.chambre-portbail.fr",3)
UsePage("Chambre d'hôtes entre Lessay et Portbail - La Varecherie")
ClickHTMLElement("A[INNERTEXT= 'Galerie Photos']")
download_image("IMG[SRC= 'http://www.chambre-portbail.fr/h']","c:\test","outside")
download_image("IMG[SRC= 'http://www.chambre-portbail.fr/highslide/images/thumbs/s']","c:\test","room")
CloseBrowser()
- 120 -
Exercise 15, Scriptweb15.src
'================================================================
' Script15
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' Exercise 15
'
' This script puts together different parts of a Web capture full project.
'================================================================
Dim searchterm$(100)
Dim description$(100)
Dim mfrname$(100)
Dim mfritem$(100)
Dim dciitem$(100)
'================================================================
function capture_one_page()
'Re-initialization of the arrays to have empty arrays at each iteration.
searchterm$()=""
description$()=""
mfrname$()=""
mfritem$()=""
dciitem$()=""
UsePage("eCatalog - Cross Reference Search ")
CaptureTableHTML("TABLE[CONTENT='Search Term']", "R2C2:R11C2", searchterm$())
CaptureTableHTML("TABLE[CONTENT='Search Term']", "R2C3:R11C3", mfritem$())
CaptureTableHTML("TABLE[CONTENT='Search Term']", "R2C4:R11C4", mfrname$())
CaptureTableHTML("TABLE[CONTENT='Search Term']", "R2C5:R11C5", dciitem$())
CaptureTableHTML("TABLE[CONTENT='Search Term']", "R2C6:R11C6", description$())
EndFunction
Function write_result()
'Data are written 20 by 20 as the captured table has 20 lines.
'In a more complex capture process, it's possible to add a parameter to the Function.
'to write n lines instead of this constant 20.
'The str$ function converts the integer variable line_number in a string which
'is concatenated using the + sign.
WriteExcel(excelfile$,"A"+str$(line_number)+":A"+str$(line_number+20),searchterm$())
WriteExcel(excelfile$,"B"+str$(line_number)+":B"+str$(line_number+20),mfritem$())
WriteExcel(excelfile$,"C"+str$(line_number)+":C"+str$(line_number+20),mfrname$())
WriteExcel(excelfile$,"D"+str$(line_number)+":D"+str$(line_number+20),dciitem$())
WriteExcel(excelfile$,"E"+str$(line_number)+":E"+str$(line_number+20),description$())
line_number=line_number+20
EndFunction
'================================================================
' Main Program
'================================================================
'Variables initialization.
line_number=2
excelfile$="C:\Program Files (x86)\WinTask\Scripts\reference.xlsx"
'Change IE to FF for starting Firefox browser or to CH for starting Chrome browser.
- 121 -
StartBrowser("IE", "http://www.donaldson.com/en/index.html")
UsePage("Donaldson Company, Inc. - Americas Region - English")
ClickHTMLElement("A[INNERTEXT= 'Part Search/Cross Re']")
UsePage("eCatalog - Cross Reference Search")
WriteHTML("INPUT TEXT[NAME= 'part_1']", "145*")
ClickHTMLElement("INPUT SUBMIT[VALUE= 'Search']")
exit=0
repeat
capture_one_page()
write_result()
If existhtmlelement("INPUT SUBMIT[VALUE= 'Next page']") = 1 then
ClickHTMLElement("INPUT SUBMIT[VALUE= 'Next page']")
Else
exit=1
EndIf
until exit = 1
- 122 -
Exercise 16, Scriptweb16.src
'================================================================
' Scriptweb16
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' This script demonstrates the difference between msgbox and msgframe to display a variable.
'================================================================
StartBrowser("IE", "www.wintask.com/demos/page-iteration1.htm")
i=2
While i <= 7
UsePage("Page Iteration 1")
msgbox("lndex i equals: "+str$(i))
ClickHTMLElement("A[INNERTEXT= '"+str$(i)+"']")
UsePage("Page Iteration "+str$(i))
ClickHTMLElement("A[INNERTEXT= 'here']")
i=i+1
Wend
CloseBrowser()
'================================================================
' The same script with msgframe.
'================================================================
StartBrowser("IE", "www.wintask.com/demos/page-iteration1.htm")
i=2
While i <= 7
UsePage("Page Iteration 1")
msgframe("lndex i equals: "+str$(i),1)
ClickHTMLElement("A[INNERTEXT= '"+str$(i)+"']")
UsePage("Page Iteration "+str$(i))
ClickHTMLElement("A[INNERTEXT= 'here']")
i=i+1
Wend
CloseBrowser()
- 123 -
Exercise 17, Scriptweb17a.src
'================================================================
' Scriptweb17a
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' This script generates a limited log file
' where only the Comment lines are written in the log file.
'================================================================
StartBrowser("IE", "www.wintask.com/demos/page-iteration1.htm")
i=2
While i <= 7
UsePage("Page Iteration 1")
Comment("lndex i equals: "+str$(i))
ClickHTMLElement("A[INNERTEXT= '"+str$(i)+"']")
UsePage("Page Iteration "+str$(i))
ClickHTMLElement("A[INNERTEXT= 'here']")
i=i+1
Wend
CloseBrowser()
'================================================================
' Scriptweb17b
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' This script creates a log file by calling a Sub defined by the programmer.
'================================================================
sub log(msg_log$)
local buffer$
buffer$=Date$()+", "+hour$()+":"+min$()+":"+sec$()+" --> "+msg_log$
write(log_file$,buffer$,CRLF)
endsub
log_file$="C:\test\script17blog.txt"
StartBrowser("IE", "www.wintask.com/demos/page-iteration1.htm")
i=2
While i <= 7
UsePage("Page Iteration 1")
log("lndex i equals: "+str$(i))
ClickHTMLElement("A[INNERTEXT= '"+str$(i)+"']")
UsePage("Page Iteration "+str$(i))
ClickHTMLElement("A[INNERTEXT= 'here']")
i=i+1
Wend
- 124 -
CloseBrowser()
- 125 -
Exercise 18, Scriptweb18.src
'================================================================
' Scriptweb18
'
' WinTask Manual Version 5.1
' © Copyright 1997-2014 TaskWare
October 2014
'
' This script demonstrates the use of the CONTENT keyword.
'================================================================
Dim dateday$(100)
Dim textnews$(100)
StartBrowser("IE", "www.wintask.com/demos/page-news.htm")
UsePage("News Page")
ret = CaptureTableHTML("TABLE[CONTENT='2014']", "R1C1:R3C1", dateday$())
ret = CaptureTableHTML("TABLE[CONTENT='2014']", "R1C2:R3C2", textnews$())
CloseBrowser()
msgbox(dateday$(0))
msgbox(textnews$(0))
- 126 -
GLOSSARY
Compiler: The WinTask program that reads a source script file and transforms it’s
instructions into a form that can be executed. WinTask automation scripts can be
compiled by hitting the Play button or selecting the Start/Run menu item before
the Executor can execute them.
Dialog Box: A window displayed by a program to gather information from the
user in order to perform a task. Dialog Boxes occasionally are used to provide task
status to the user.
Editor: The WinTask program that serves as the focal point for the development,
compilation and execution of automation scripts. The Editor provides access to
Recording mode, the Synchronization wizards and other tools which aid in the
creation and maintenance of automation scripts.
Executor (TaskExec): The WinTask program that interprets the automation
instructions in a .ROB file. Double-clicking a file with a .ROB extension will invoke
the WinTask Executor and begin executing the compiled automation script.
HTML Descriptor: A unique identifier for any HTML object displayed on a Web
page. It includes the HTML tag and any meaningful text.
Log: A file that documents the execution and result of script statements during
the execution of an automation script. The log file can be reviewed to determine
why a particular script failed to run to completion.
Macro: (See Script).
Recording Mode: An operational mode of the WinTask Editor that records a
user’s keyboard and mouse actions as script statements. Recording mode allows
the user to rapidly develop automation scripts.
.ROB: Files with a .ROB extension are created by the WinTask Compiler when
compiling an automation script file. The WinTask Executor reads and executes the
instructions contained in a .ROB file.
Script: A collection of WinTask language script statements, which when compiled
and executed, automate an application or process. WinTask script files use the
.SRC extension.
Spy: The WinTask program tool that determines the internal Windows Name, a
control name, or an HTML descriptor. This tool is needed to distinguish between
the numerous elements that may populate the Windows desktop.
Window Name: The unique identifier of a window displayed on desktop, usually
the text found in the title bar. The Window Name typically consists of the program
name and the name of the document is has open. WinTask uses the Window
Name to distinguish between the numerous windows that may populate the
desktop.
WinTask Floating Toolbar: A small toolbar displayed during Recording mode.
The toolbar provides access to the WinTask Editor functions that the user may
need during a recording session. The toolbar provides access to the Spy tool, the
Synchronization wizards and a Stop button
- 127 -
- 128 -
Index
#ActionTimeout ............................................ 36
#IgnoreErrors ............................................... 36
#UseExact ...................................................... 37
Arrays ............................................................... 34
Compilation Errors....................................... 74
Compiler
TaskComp ..................................................... 6
Dialog box Editor ........................................... 7
Editor
TaskEdit ......................................................... 6
Execution Errors ........................................... 74
Executor
TaskExec ....................................................... 7
Exist() .............................................................. 42
Forms automation ....................................... 56
Function/ExitFunction/EndFunction ...... 60
Include ................................................................ 74
Integers ........................................................... 33
Iteration (Loop) ............................................ 40
Kill() .................................................................. 42
Language Functions .................................... 31
- 129 -
Operators ........................................................ 34
Read() .............................................................. 43
ReadExcel ....................................................... 43
Real numbers ................................................ 34
Repeat/Until ................................................... 40
Spy ...................................................................... 7
Strings .............................................................. 33
Sub/ExitSub/EndSub .................................. 58
Synchronisation - Time ...................................... 17
Synchronization .............................................. 7
Synchronization – Date/Hour ............................. 17
Synchronization - Image..................................... 16
Synchronization – OCR Text ............................. 16
Synchronization - Text ....................................... 16
Synchronization - Window................................. 16
System Variables ......................................... 33
Terminating a Script ................................... 13
Variables.......................................................... 32
Wait for an action ............................................... 17
While/Wend .................................................... 40
WriteExcel ....................................................... 43