Applies to TestComplete 14.20, last modified on September 11, 2019

Description

The Exists property tells whether a given object still exists in the system. If it does not exist, Exists is False; else, True.

Declaration

TestObj.Exists

Read-Only Property Boolean
TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section

Applies To

All processes, windows, controls and onscreen objects.

View Mode

To view this property in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Property Value

True if the object exists in the system; else, False.

Remarks

  • For mapped objects, the property does not refresh the mapping information to check whether the object’s properties match the recognition attributes. Call the RefreshMappingInfo method before using the Exists property. For more information, see Refresh Name Mapping Cache.

  • If TestComplete fails to find the object whose Exists property you are checking, an error will occur. For example, the code below will fail if the process TestedApp does not exist in the system:

    JavaScript, JScript

    // If the process does not exist, an error will occur
    if (! Sys.Process("TestedApp").Exists ) 
      …

    Python

    # If the process does not exist, an error will occur
    if not Sys.Process("TestedApp").Exists:
      …

    VBScript

    ' If the process does not exist, an error will occur
    If Not Sys.Process("TestedApp").Exists Then
      …
    End If

    DelphiScript

    // If the process does not exist, an error will occur
    if not Sys.Process('TestedApp').Exists then
      …

    C++Script, C#Script

    // If the process does not exist, an error will occur
    if (! Sys["Process"]("TestedApp")["Exists"] )
      …

    Do not use Exists this way. Use the WaitNNN methods to get the needed object first. If the requested object does not exist, this method will return a stub object whose Exists property will be False. You can view the sample code that shows how to do this in the Example section below.

    To learn more, see Checking Whether an Object Exists From Scripts.

Example

The following code checks whether a process exists and if it does not, posts a warning to the test log:

JavaScript, JScript

if (! Sys.WaitProcess("WinWord").Exists )
  Log.Warning("Process MS Word is not found");

Python

if not Sys.WaitProcess("WinWord").Exists:
  Log.Warning("Process MS Word is not found")

VBScript

If Not Sys.WaitProcess("WinWord").Exists Then
  Log.Warning "Process MS Word is not found"
End If

DelphiScript

if not Sys.WaitProcess('WinWord').Exists then
  Log.Warning('Process MS Word is not found');

C++Script, C#Script

if (! Sys["WaitProcess"]("WinWord")["Exists"] )
  Log["Warning"]("Process MS Word is not found");

See Also

Find Method
FindId Method
Checking Whether an Object Exists

Highlight search results