Touching a Button

Applies to TestComplete 15.63, last modified on April 22, 2024

Simulating Touch Actions

To simulate touching a button in an iOS application, you can use the TouchButton method of the iOS Button object or the Touch method that is available for all tested mobile objects. These methods simulate a single short touch on a button.

The following example demonstrates how to perform a touch via these methods:

JavaScript, JScript

function Test()
{

  // Select the mobile device
  Mobile.SetCurrent("iPhone");

  // Obtain the button object
  var p = Mobile.Device().Process("SampleApp");
  var button = p.Window(0).Button("Sample Button");

  // Touch the button
  button.Touch();
  button.TouchButton();

}

Python

def Test():

  # Select the mobile device
  Mobile.SetCurrent("iPhone")

  # Obtain the button object
  p = Mobile.Device().Process("SampleApp")
  button = p.Window(0).Button("Sample Button")

  # Touch the button
  button.Touch()
  button.TouchButton()

VBScript

Sub Test

  ' Select the mobile device
  Mobile.SetCurrent("iPhone")

  ' Obtain the button object
  Set p = Mobile.Device.Process("SampleApp")
  Set button = p.Window(0).Button("Sample Button")

  ' Touch the button
  button.Touch
  button.TouchButton

End Sub

DelphiScript

procedure Test();
var p, button;
begin

  // Select the mobile device
  Mobile.SetCurrent('iPhone');

  // Obtain the button object
  p := Mobile.Device.Process('SampleApp');
  button := p.Window(0).Button('Simple Button');

  // Touch the button
  button.Touch();
  button.TouchButton();

end;

C++Script, C#Script

function Test()
{

  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");

  // Obtain the button object
  var p = Mobile["Device"]["Process"]("SampleApp");
  var button = p["Window"](0)["Button"]("Sample Button");

  // Touch the button
  button["Touch"]();
  button["TouchButton"]();

}
Note: You can touch a button only if it is enabled. To get information on how to determine a button’s state, see the Checking a Button's State topic.

Simulating Long Touch Actions

To simulate touching a button in an iOS application, you can use the LongTouchButton method of the iOS Button object or the LongTouch method that is available for all tested mobile objects. These methods simulate a single long touch over a button.

The following example demonstrates how to use these methods to perform a long touch:

JavaScript, JScript

function Test()
{

  // Select the mobile device
  Mobile.SetCurrent("iPhone");

  // Obtain the button object
  var p = Mobile.Device().Process("SampleApp");
  var button = p.Window(0).Button("Sample Button");

  // Touch the button
  button.LongTouch();
  button.LongTouchButton();

}

Python

def Test():

  # Select the mobile device
  Mobile.SetCurrent("iPhone")

  # Obtain the button object
  p = Mobile.Device().Process("SampleApp")
  button = p.Window(0).Button("Sample Button")

  # Touch the button
  button.LongTouch()
  button.LongTouchButton()

VBScript

Sub Test

  ' Select the mobile device
  Mobile.SetCurrent("iPhone")

  ' Obtain the button object
  Set p = Mobile.Device.Process("SampleApp")
  Set button = p.Window(0).Button("Sample Button")

  ' Touch the button
  button.LongTouch
  button.LongTouchButton

End Sub

DelphiScript

procedure Test();
var p, button;
begin

  // Select the mobile device
  Mobile.SetCurrent('iPhone');

  // Obtain the button object
  p := Mobile.Device.Process('SampleApp');
  button := p.Window(0).Button('Simple Button');

  // Touch the button
  button.LongTouch();
  button.LongTouchButton();

end;

C++Script, C#Script

function Test()
{

  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");

  // Obtain the button object
  var p = Mobile["Device"]["Process"]("SampleApp");
  var button = p["Window"](0)["Button"]("Sample Button");

  // Touch the button
  button["LongTouch"]();
  button["LongTouchButton"]();

}

Simulating Touch Actions in Keyword Tests

To simulate touching a button from keyword tests, call the methods described above by using the On-Screen Action or Call Object Method operation. See Calling Object Methods.

See Also

Working With iOS Button Controls
Checking a Button's State
Touch Action (Mobile Objects)
TouchButton Action (Mobile Controls)

Highlight search results