Exists Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Checks whether a control specified by its image in the Image Repository is currently displayed on your PC desktop or your current mobile device’s screen. Unlike the ChekImage method, the Exists method does not post any messages to the test log.

Declaration

TestObj.Exists(SearchArea)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
SearchArea [in]    Optional    Object    
Result Boolean

Applies To

View Mode

This method is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.

Parameters

The method has the following parameter:

SearchArea

Specifies the area, within which the method will search for the image. Can take the following values:

If the parameter is omitted, first the method will search for the image on the screen of the current mobile device (you can set the current device by calling Mobile.SetCurrent in your script code, or the Select Device or Device Loop operation in your keyword test).

If the image is not found, the method will search for the image on your PC desktop.

Result Value

The method returns True if the control was found. Otherwise, it returns False.

Remarks

The Exists method searches for the image pixel by pixel. For the search to be successful, the whole control should be visible on the screen. If the control is visible partially, or if it is overlapped by some other image (for instance, by a menu), the method returns False.

Example

The following code snippet either simulates touching the given control (if it exists on the screen) or posts an error message if the control was not found:

JavaScript, JScript

...
if (ImageRepository.calculator.Button_Plus.Exists())
  ImageRepository.calculator.Button_Plus.Touch();
else Log.Message("The Plus button was not found on the current screen.");
...

Python

# ...
if ImageRepository.calculator.Button_Plus.Exists():
  ImageRepository.calculator.Button_Plus.Touch()
else:
  Log.Message("The Plus button was not found on the current screen.")
# ...

VBScript

...
If (ImageRepository.calculator.Button_Plus.Exists) Then
  ImageRepository.calculator.Button_Plus.Touch()
Else Log.Message("The Plus button was not found on the current screen.")
End If
...

DelphiScript

...
if (ImageRepository.calculator.Button_Plus.Exists()) then
  ImageRepository.calculator.Button_Plus.Touch()
else Log.Message('The Plus button was not found on the current screen.');
...

C++Script, C#Script

...
if (ImageRepository["calculator"]["Button_Plus"]["Exists"]())
  ImageRepository["calculator"]["Button_Plus"]["Touch"]();
else Log["Message"]("The Plus button was not found on the current screen.");
...

See Also

Testing Android Applications (Legacy)
ImageSetItem Object
CheckImage Method
Image-Based Testing

Highlight search results