Drag Method

Applies to TestComplete 15.47, last modified on January 20, 2023
This method is available in legacy mobile tests that work with devices connected to the local computer. To learn how to simulate user actions in newer cloud-compatible mobile tests, see the Simulating user actions in tests section.

Description

Simulates touching the screen at the specified point for the specified period of time and then moving a fingertip to the specified point. The touch coordinates are relative to the control position.

Declaration

TestObj.Drag(StartX, StartY, DistanceX, DistanceY, FromHoldDuration)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
StartX [in]    Required    Integer    
StartY [in]    Required    Integer    
DistanceX [in]    Required    Integer    
DistanceY [in]    Required    Integer    
FromHoldDuration [in]    Optional    Integer Default value: 0   
Result None

Applies To

The method is applied to the following object:

All Android, iOS and Xamarin.Forms objects

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 parameters:

StartX

Specifies the horizontal coordinate (in pixels) of the start point of the drag action. This coordinate is specified relative to the top-left corner of the underlying control. If the coordinate is omitted, the touch is simulated in the center of the control.

StartY

Specifies the vertical coordinate (in pixels) of the start point of the drag action. This coordinate is specified relative to the top-left corner of the underlying control. If the coordinate is omitted, the touch is simulated in the center of the control.

DistanceX

Specifies the horizontal distance of the drag action.

DistanceY

Specifies the vertical distance of the drag action.

FromHoldDuration

Specifies the touch delay (in milliseconds).

Result Value

None.

Example

The code below demonstrates how to use the Drag method to simulate dragging across the control on a mobile device:

JavaScript, JScript

function Test()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Obtain the PickerView object
  var p = Mobile.Device().Process("SampleApp");
  var iOSObject = p.Window.TableView(0);
  
  iOSObject.drag(5,5, 0, 500);
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the PickerView object 
  p = Mobile.Device().Process("SampleApp")
  iOSObject = p.Window.TableView(0)
  
  iOSObject.drag(5,5, 0, 500)

VBScript

Sub Test()

  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the PickerView object
  var p = Mobile.Device.Process("SampleApp")
  var iOSObject = p.Window.TableView(0)
  
  Call iOSObject.drag(5,5, 0, 500)
End Sub

DelphiScript

procedure Test();
var
  p, iOSObject;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the PickerView object
  p := Mobile.Device.Process('SampleApp');
  iOSObject := p.Window.TableView(0);
  
  iOSObject.drag(5,5, 0, 500);
end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");
  // Obtain the PickerView object
  var p = Mobile["Device"].Process("SampleApp");
  var iOSObject = p["Window"].TableView(0);
  
  iOSObject["drag"](5,5, 0, 500);
}

See Also

Testing Mobile Applications

Highlight search results