TouchAndHold Method

Applies to TestComplete 14.40, last modified on April 22, 2021

Description

Simulates touching the screen at the specified point for the specified period of time.

Declaration

ProgObj.TouchAndHold(XYDelay)

ProgObj An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section
X [in]    Required    Integer    
Y [in]    Required    Integer    
Delay [in]    Optional    Integer Default value: 1000   
Result None

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameters:

X

Specifies the horizontal coordinate (in pixels) of the point where a touch will be simulated.

Y

Specifies the vertical coordinate (in pixels) of the point where a touch will be simulated.

Delay

Specifies the time (in milliseconds) for which the device's screen will be touched.

Result Value

None.

Remarks

This method is asynchronous. This means that TestComplete continues running the test, no matter whether it has finished or not. For information on how it may affect testing on Android devices, see Possible Issues.

Example

The example below demonstrates how to use the TouchAndHold method to simulate touching the screen of a mobile device:

JavaScript, JScript

function Test()
{
  // Specify the current device
  Mobile.SetCurrent("MyDevice");

  // Launch the tested application
  …

  // Simulate user actions
  …
  Mobile.Device().TouchAndHold(125, 75);
  …

}

Python

def Test():
  # Specify the current device
  Mobile.SetCurrent("MyDevice")

  # Launch the tested application
  # ...

  # Simulate user actions
  # ...
  Mobile.Device().TouchAndHold(125, 75)
  # ...

VBScript

Sub Test

  ' Specify the current device
  Call Mobile.SetCurrent("MyDevice")

  ' Launch the tested application
  …

  ' Simulate user actions
  …
  Call Mobile.Device.TouchAndHold(125, 75)
  …

End Sub

DelphiScript

procedure Test;
begin
  // Specify the current device
  Mobile.SetCurrent('MyDevice');

  // Launch the tested application
  …

  // Simulate user actions
  …
  Mobile.Device.TouchAndHold(125, 75);
  …

end;

C++Script, C#Script

function Test()
{
  // Specify the current device
  Mobile["SetCurrent"]("MyDevice");

  // Launch the tested application
  …

  // Simulate user actions
  …
  Mobile["Device"]["TouchAndHold"](125, 75);
  …

}

See Also

Testing Mobile Applications
Drag Method
Move Method (Device object)
TouchAndHold Method
AndroidDevice Object
iOSDevice Object

Highlight search results