Home > Enhancing Scripts > Naming Objects, Spy Tool

Naming Objects, Spy Tool

The Spy tool included in WinTask x64 allows you to find the name of a window and the parameters for the UseWindow function. It is used too for generating the HTML descriptor of HTML elements displayed on a Web page.  
It is used too for generating the UIA descriptor of elements exposed to the UI Automation framework if the application supports it.

Video: How to use Spy on a Windows application
Video: How to use Spy on a web page
Video: How to use Spy on an UI Automation object

To launch Spy tool, click  icon in WinTask x64 Editor toolbar or select Start/Spy menu. Spy main window is displayed:

Click Spy button. Move the mouse on the desktop, when a window is found, the mouse cursor changes to a cross-hair pointer. Click once to populate Spy window fields for this specific window. The window name is shown in the "Window name" field. Other window identifiers are listed below:
Field name   Content
 UseWindow  Argument for UseWindow function
 Appl          Application name
 Module  Executable module name
 Class      Window class
 Title  Window title
 Index  Index of the control (when the same control
 is used several times inside the window)
 Instance      Instance number (if several instances of the same window are loaded)
 Handle  Window handle in hexa - Note that GetTopWindowHandleGetFocusWindowHandle and GetWindowHandle function return the
handle as an integer 

For example, Spy on an emtpy notepad window displays:


It is possible to truncate this window name in the Window name field ; delete rightmost characters if you want to use a truncated window name in a UseWindow function. Click Validate button to check that the window name is still correct. If window name changes from one replay to another, truncate the window name to keep only the beginning of the window name which does not change.

Click Paste button to paste the window name found by the SPY tool into the script. The paste is done where the cursor is in the Editor window, so before pasting, place the cursor in a new line. This pasted window name can then be used as argument for the UseWindow function.

Spy tool on a Web page

If Spy tool is used on a Web page, the Web Information part of Spy window is filled too. For example, if you load www.wintask.com/demos and if you use Spy to find the HTML descriptor of the Form link, the Spy window is filled like that after having moved the mouse on Form text and clicked once:

HTML tag field returns the tag name for the HTML element where the mouse is. 

The Cursor position fields give the mouse coordinates in pixels relative to the top left corner of the browser client window and relative to the top left corner of the screen. They can be used for generating easily the ClickMouse function.

The HTML attributes box gives the different attributes which can be used for generating the HTML descriptor. Select the one that you want to use.

Descriptor INDEX returns the INDEX number which will be used in the HTML descriptor (when two HTML elements have the same descriptor, an INDEX is added for identifying each element uniquely - see HML descriptor topic).

If the HTML element is an element containing text which can be captured by WinTask x64 (Table, Paragraph, ...), Change CONTENT button can be used to change the CONTENT keyword.

The Descriptor field contains the HTML descriptor as you have generated it using the fields above. Click Paste button to paste it into the script.

Spy tool on an application exposed to UI Automation

If Spy tool is used on an element exposed to UI Automation framework, the UI Automation Information part of Spy window is filled too.

Note that to find the UIA descriptor of an element displayed only after a menu selection, you need to check Delay the selection for 3 seconds checkbox. Click Spy button and during those 3 seconds delay, make display the element you want to spy and then spy it after the 3 seconds delay.

For example, if you load www.wintask.com/demos using Internet Explorer, then click File link. The IE Download window is displayed at the bottom of the main IE window and the UI Automation Information part of Spy is filled as below when you spy the Save button:

The UIA descriptor field gives the UIA descriptor for the spyed element. How is built the UIA descriptor is explained in Improving Object Recognition by using UI Automation technology  topic.

Click Change UIA descriptor if you want to change it, a new window Change UIA descriptor is displayed and you can select/deselect the properties you want to use in the UIA descriptor.

Click Paste UIA  descriptor button to paste it into the script.