Applies to TestComplete 14.10, last modified on June 5, 2019

This topic explains how you can check the state of an application’s object. For instructions on verifying that an object exists, see Checking Whether an Object Exists. To learn how to wait until the object state changes, see Waiting for Object State Changes.

Checking Object State in Keyword Tests

In keyword tests, you can check the current state of an application’s object using the If Object operation. It allows you to check if the object is enabled or disabled, visible or invisible and so on. Below are step-by-step instructions on configuring this operation:

  • Add the If Object operation to your keyword test. TestComplete will display the Operation Parameters wizard.

  • Specify the object whose state you want to check, and press Next.

  • Choose the object state you want to test. The operation lets you test the following states:

    • Exists
    • Does not exist
    • Visible
    • Invisible
    • Enabled
    • Disabled
  • Click Finish to finish configuring the If Object operation.

To specify the operations to execute if the object has the specified state:

  • Add the needed operations to the test as child items of the If Object operation.

To specify the operations to execute if the object does not have the needed state:

  • Add the Else operation right after the If Object operation.

  • Add the needed operations as child items of the Else operation.

The following image shows a sample keyword test that checks if the Notepad’s window is visible and if so, types some text in it:

A keyword test with the If Object operation

As you can see, the If Object operation lets you test only limited number of object states. To perform an advanced state check, use the Property Checkpoint or If … Then operation.

Checking Object State in Scripts

To check an object’s state in script code, write an if … then statement that obtains the value of the object’s property indicating the desired state and performs the needed actions if the check succeeds or fails. Property checkpoints will generate the needed code for you automatically.

Below is an example of checking that a window is visible on screen:

JavaScript, JScript

var w = Sys.Process("Notepad").Window("Notepad");

if (w.VisibleOnScreen)
Log.Error("The Notepad window is invisible.");


w = Sys.Process("notepad").Window("Notepad")
if (w.VisibleOnScreen):
  Log.Error("The Notepad window is invisible")


Dim w
Set w = Sys.Process("Notepad").Window("Notepad")

If w.VisibleOnScreen Then
  Log.Error "The Notepad window is invisible."
End If


var w;
  w := Sys.Process('Notepad').Window('Notepad');

  if w.VisibleOnScreen then
     Log.Error('The Notepad window is invisible.');

C++Script, C#Script

var w = Sys["Process"]("Notepad")["Window"]("Notepad");

if (w["VisibleOnScreen"])
   Log["Error"]("The Notepad window is invisible.");

See Also

Working With Application Objects and Controls
Common Tasks
Checking Whether an Object Exists
Waiting for Object State Changes
If Object Operation
If... Then Operation
Property Checkpoint Operation
About Property Checkpoints

Highlight search results