If - Window exists

Declaration

<AMIF ACTIVITY="window_exists" WINDOWTITLE="text" WINDOWCLASS="text" WINDOWHANDLE="text" ACCESSIBILITYENGINE="text (options)" CONTAINSOBJECT="YES/NO" OBJECTPROPERTYSETS="Toolkit=text,Type=text,Class=text,FrameworkId=text,Name=text,AutomationId=text,Value=text,Role=text,Description=text,X=number,Y=number,Width=number,Height=number,IndexInParent=text,ParentPath=text,Occurrence=number" ALLOWHIDDEN="YES/NO" WINDOWTITLEVARIABLE="text" WINDOWCLASSVARIABLE="text" WINDOWHANDLEVARIABLE="text" RESULTDATASET="text" ACTION="text (options)" CHILDWINDOW="YES/NO" />

Related Topics   

Description

Determines the state of a window and returns TRUE or FALSE depending on the outcome. If TRUE, the steps immediately following this step is executed. If FALSE, execution follows the next Else statement. Optionally, this activity populates a dataset with multiple information about the specified process.

NOTE: All If activities must be followed at some point with an End If step to mark the end of the code block that is to be executed if the expression is TRUE. For ease of use, by default, any If activity added to the Task Builder's Steps panel is always followed by an End If activity.

Practical usage

Commonly used to set up conditional steps to be executed if a specified window is opened, closed, focused, or in the background.

Parameters

General

This activity comprises Automate Desktop's Window Dissection technology to facilitate the discovery of existing windows and their controls. To select the target window:

  1. Make certain the window is open and in the foreground (in front of all other open windows).
  2. Drag and release the magnifier icon over the window. If the window is supported by this activity, a green border will appear around it.
  3. Upon releasing the icon, identified window properties are populated onto the editor. These properties can be enabled / disabled or further modified.
Property Type Required Default Markup Description
By window title Text Yes (Empty) WINDOWTITLE="*Explorer" If enabled, indicates the title of the window to evaluate. If disabled, the window title will be ignored. This parameter supports wildcard characters (that is, * or ?). For example, entering *Notepad* would include any window with the word Notepad in its title.
By window   class Text No (Empty) WINDOWCLASS="Outlook Browser" If enabled, indicates the class of the window to evaluate. If disabled, the window class will be ignored. A window class is a set of attributes that the system uses as a template to create a window. Every window is a member of a class and all window classes are process specific. This parameter supports wildcard characters (that is, * or ?). For example, entering *IE* would include any window containing IE its class.
By window handle Number No (Empty) WINDOWHANDLE="555735" If enabled, indicates the handle of the window to evaluate. If disabled, the window handle will be ignored. A window handle is numeric code that uniquely identifies a window. This parameter supports wildcard characters (that is, * or ?).
Accessibility engine Text (options) No Auto
  • ACCESSIBILITYENGINE="auto"
  • ACCESSIBILITYENGINE="ui_automation"
  • ACCESSIBILITYENGINE="active"
  • ACCESSIBILITYENGINE="java"
  • ACCESSIBILITYENGINE="ie"
The accessibility engine that this activity will use to programmatically gather accurate information about a user interface in order to interact with it. The available options are:
  • Auto - Starting with UI Automation, Automate Desktop detects which accessibility engine to use based on the control's properties.
    NOTE: Some controls may not be compatible with this option and will require one of the other accessibility engine options to be manually selected for best results.
  • UI Automation - UI Automation will be used, which is Microsoft's standard for exposing information about its user interface.
  • Active - Active Accessibility will be used, which uses an older Microsoft engine for exposing information about its user interface.
  • Java - Java Access Bridge will be used, which is a technology that enables certain Java applications and applets to be visible to assistive technologies on Microsoft Windows systems.
  • Internet Explorer - Internet Explorer DOM will be used, which is the Document Object Model used to represent objects in a web page (that is, text, images, headers, links, etc.).
Condition Text (Options) Yes Window Exists
  • ACTION="open"
  • ACTION="close"
  • ACTION="focus"
  • ACTION="background"
Specifies the window condition to check. The available options are:
  • Window exists - - The If block will be executed if the window exists (or is open)
  • Window does not exist - The If block will be executed if the window does not exist (or is closed).
  • Window is focused- The If block will be executed if the window is open and focused (or in the foreground).
  • Window is not focused - The If block will be executed if the window is open but unfocused (or in the background).
Window is a Child Window Yes/No No No CHILDWINDOW="YES" If enabled, specifies that the window to evaluate is a child window. A child is a secondary window that is displayed over the parent (main) window of a program or application. This parameter is useful for Multi-Document Interface (MDI) applications, which include a series of windows contained within one parent window.

Window Contents

If multiple windows with the same title exists, it may be necessary to use Automate Desktop's Object Editor to specify additional criteria, such as unique objects, controls or properties, in order to distinguish one window from another. To identify additional elements, enable Window must contain the following objects, and then click Add to open the Object Editor dialog. Thereafter, do one of the following:

  1. Drag and release the magnifier icon over the desired object or control. The Object properties grid becomes populated with a list of name / value pairs unique to that object. Individual values can be enabled / disabled according to preference.
  2. Click Browse to traverse the list of available objects / controls for the selected window. Select the desired object from the Window contents column, and then click OK. The Object properties grid becomes populated with a list of defined properties unique to that object. Individual values can be enabled or disabled according to preference.

Available object properties are described below:

Property Type Required Default Markup Description
Toolkit Text No (Empty)
  • TOOLKIT=UIAutomation
  • TOOLKIT=WindowsAccessibility
  • TOOLKIT=JavaAccessibility

If enabled, specifies that the toolkit (a set of basic building units for graphical user interfaces) will be examined when determining a matching object. If disabled, the toolkit will be ignored.

The toolkit that appears is based on the Accessibility engine used:

  • UI Automation - UIAutomation
  • Active - WindowsAccessibility
  • Java - JavaAccessibility
  • Internet Explorer - WindowsAccessibility
Type Text No (Empty) TYPE=PushButton If enabled, specifies that the object's type (that is, Button, Checkbox, Trackbar) will be examined when determining a matching object. If disabled, the type will be ignored.
Class Text No (Empty) CLASS=SysTreeView32 If enabled, specifies that the object's class (that is, XTPToolBar, SysTreeView, MDIClient) will be examined when determining a matching object. If disabled, the class will be ignored.
FrameworkId Text No (Empty) FRAMEWORKID=WPF If enabled, specifies that the object's framework ID (the framework technology used to create the object) will be examined when determining a matching object. If disabled, the framework ID will be ignored.
Name Text No (Empty) NAME=Cancel If enabled, specifies that the object's name (a unique identifier for an object) will be examined when determining a matching object. If disabled, the name will be ignored.
AutomationId Text No (Empty) AUTOMATIONID=System If enabled, specifies that the object's automation ID (a unique identifier for an object) will be examined when determining a matching object. If disabled, the automation ID will be ignored.
Value Text No (Empty) VALUE=1 If enabled, specifies that the object's value (which usually coincides with the Name property) will be examined when determining a matching object. If disabled, the value will be ignored.
Role Text No (Empty) ROLE=desktop pane If enabled, specifies that the object's role type (the control type provided by the Java Accessibility bridge) will be examined when determining a matching object. If disabled, the role type will be ignored.
Description Text No (Empty) DESCRIPTION=JScrollPane If enabled, specifies that the object's description (the description given for an object) will be examined when determining a matching object. If disabled, the description will be ignored.
X Number No (Empty) X=80 If enabled, specifies that the object's X coordinate (a given number of pixels along the horizontal axis of a window starting from the extreme left side) will be examined when determining a matching object. If disabled, the X coordinate will be ignored.
NOTE: The X and Y coordinates are relative to the specified window as opposed to the screen.
Y Number No (Empty) Y=90 If enabled, specifies that the object's Y coordinate (a given number of pixels along the vertical axis of a window starting from the top-most portion) will be examined when determining a matching object. If disabled, the Y coordinates will be ignored.
NOTE: The X and Y coordinates are relative to the specified window as opposed to the screen.
Width Number No (Empty) WIDTH=711 If enabled, specifies that the object's pixel width will be examined when determining a matching object. If disabled, the pixel width will be ignored.
Height Number No (Empty) HEIGHT=42 If enabled, specifies that the object's pixel height will be examined when determining a matching object. If disabled, the pixel height will be ignored.
IndexInParent Text No (Empty) INDEXINPARENT=1 If enabled, specifies that the object's index in parent number (the numeric identifier of a child object located within a parent object) will be examined when determining a matching object. If disabled, the index in parent number will be ignored.
ParentPath Text No (Empty) PARENTPATH=50032|50033 If enabled, specifies that the object's parent path (the sequence of control type identifiers that lead to the object) will be examined when determining a matching object. If disabled, the parent path will be ignored.
Occurrence Number No (Empty) OCCURRENCE=1 If enabled, specifies that the object's occurrence (the numeric identifier of an object, useful when multiple matching objects are found) will be examined when determining a matching object. If disabled, the occurrence will be ignored.

Advanced

 
PropertyTypeRequiredDefaultMarkupDescription
Include hidden windowsYes/NoNoYesALLOWHIDDEN="YES"If enabled, hidden (non-visible) windows will be included in the window search. Disabled by default.
Populate window title in variableTextNo(Empty)WINDOWTITLEVARIABLE="theTitle"If enabled, specifies the name of an existing variable that should be populated with the title of the window that was focused.
Populate window class in variableTextNo(Empty)WINDOWCLASSVARIABLE="theClass"If enabled, specifies the name of an existing variable that should be populated with the class of the window that was focused.
Populate window handle in variableTextNo(Empty)WINDOWHANDLEVARIABLE="theHandle"If enabled, specifies the name of an existing variable that should be populated with the handle of the window that was focused.
Create and populate datasetTextNo(Empty)RESULTDATASET="DatasetName"If enabled, specifies the name of a dataset to be created and populated with information about the window that was focused. More on the fields that this dataset creates can be found under Datasets below.

Description

Error Causes

On Error

Additional notes

Datasets

A dataset is a multiple column, multiple row container object. This action creates and populates a dataset with the following fields (rows):

 
NameData TypeReturn Value
theDataset.TitleTextReturns the title of the window that caused this step to execute.
theDataset.ClassTextReturns the class of the window that caused this step to execute.
theDataset.HandleNumberReturns the handle of the window that caused this step to execute.

Example

NOTE:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

Description:

This example task will determine if a window with the word "Google" in its title is currently open. If it is, a Speak action will speak the words "The window is open." If it is not, the Speak action will speak the words "The window is not open" instead.

Copy
<AMIF ACTIVITY="window_exists" WINDOWTITLE="*Google*" />
<AMSPEECH TEXT="The window is open" VOLUME="100" SPEED="50" />
<AMELSE />
<AMSPEECH TEXT="The window is not open" VOLUME="100" SPEED="50" />
<AMIF ACTIVITY="end" />