Home > FAQ > Useful Basic Tasks when writing a script > How do I find the window which has the focus?

How to use UI Automation functions

WinTask x64 supports now the UI Automation technology and can use UI Automation to obtain information on UI elements of the application to automatize. Properties of buttons, check boxes, menus and menu items, data grids, list boxes and other controls can be retrieved using UI Automation technology.

This article explains how it works on an example : the IE File Download small window at the bottom of the IE window when you download a file from the web.

Go to www.wintask.com/demos using Internet Explorer (under a x64 version of Windows, do not use Internet Explorer (64-bit) but use Internet Explorer). The WinTask web demonstration site is displayed:

 
 
 
Click File link in the web page, this link downloads a test file. The IE Download small window appears at the bottom:

 

These objects, such as Open, Save buttons in this small window can be accessed only through their UIA descriptor and can be clicked only by the ClickUIA WinTask x64 function. So for example we will use Spy tool to find the UIA descriptor for the Save button and use this UIA descriptor to generate the ClickUIA syntax.


Launch Spy tool from WinTask x64 Editor window. The Spy window is displayed as shown below:

 

Click Spy button. Mouse pointer shape changes. Move the mouse pointer on the Save button in the Download small window at the bottom of the IE window, you get the following information:

 

The UIA descriptor for the Save button is generated in the UIA descriptor field, click Paste UIA descriptor button to paste it into the script. Here is the code pasted into the Editor window:

"[APP='iexplore.exe',CLASS='DirectUIHWND',AUTOID='IENotificationBar'][NAME='Save',ROLE='split button']"

You only have to add the word « ClickUIA » before the UIA descriptor and add the necessary parenthesis to generate the ClickUIA statement which at replay will click the Save button:

ClickUIA("[APP='iexplore.exe',CLASS='DirectUIHWND',AUTOID='IENotificationBar'][NAME='Save',ROLE='split button']")

Click Play icon to test this one-line script, you see the Save button clicked and the test file is now saved.


If now you want to select Save as in this small Download window, the script must first click the small arrow at the right of the Save button to open the context menu, and then select the Save as option. Spy tool must be used twice and two ClickUIA statements must be used for those two clicks.

Click Spy button. Mouse pointer shape changes. Move the mouse pointer on the small arrow at the right of the Save button, Spy screen shows this information:

 
 

Click Paste UIA descriptor to paste the generated UIA descriptor into the script. The pasted line is:

"[APP='iexplore.exe',CLASS='DirectUIHWND',AUTOID='IENotificationBar'][NAME='Save',ROLE='split button'][ROLE='split button']"

Add the word « ClickUIA » before the UIA descriptor and add the necessary parenthesis to generate the ClickUIA statement which at replay will click the arrow and so open the Context menu:

ClickUIA("[APP='iexplore.exe',CLASS='DirectUIHWND',AUTOID='IENotificationBar'][NAME='Save',ROLE='split button'][ROLE='split button']")

Now Spy tool needs to be used again to find the UIA descriptor for the Save as menu option.

Call Spy again. As you need to click the arrow to make display the Save as button, check Delay the selection for 3 seconds checkbox in order you have some time to click the arrow and move the mouse on the Save as button which appears when the arrow is clicked:

 

Click Spy button, click the small arrow and when the context menu is displayed move the mouse on the Save as button, click once the mouse left button to generate the UIA descriptor:



Click Paste UIA descriptor button, this line is pasted into the script:

"[APP='iexplore.exe'][NAME='Save as',ROLE='menu item']"

Add the word « ClickUIA » before the UIA descriptor and add the necessary parenthesis to generate the ClickUIA statement which at replay will click the Save as button:

ClickUIA("[APP='iexplore.exe'][NAME='Save as',ROLE='menu item']")

Click the Play icon to replay the two lines script, you see the arrow clicked and the Save as option clicked.