Applies to TestComplete 14.10, last modified on May 13, 2019

A alert view controls contain buttons. A typical control contains some message (question) and the OK and Cancel buttons that a user can press. To simulate pressing a button, you use the TouchButton action of the iOS AlertView test object. This action “touches” the button that is specified by its index (from 0) or caption. You can use this action both in script code and in keyword tests.

In Script Code

The following code snippet simulates a touch on the OK button of an alert view control:

JavaScript, JScript

function Test()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Obtain the AlertView object
  var p = Mobile.Device().Process("SampleApp");
  var alertview = p.Window(2).AlertView("Alert title");

  // Touch the "OK" button
  alertview.TouchButton("OK");
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the AlertView object 
  p = Mobile.Device().Process("SampleApp")
  alertview = p.Window(2).AlertView("Alert title")

  # Touch the "OK" button
  alertview.TouchButton("OK")

VBScript

Sub Test()
  Dim p, AView
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the AlertView object
  Set p = Mobile.Device.Process("SampleApp")
  Set AView = p.Window(2).AlertView("Alert title")

  ' Touch the "OK" button
  Call AView.TouchButton("OK")
End Sub

DelphiScript

procedure Test();
var
  p, alertview;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the AlertView object
  p := Mobile.Device.Process('SampleApp');
  alertview := p.Window(2).AlertView('Alert title');

  // Touch the "OK" button
  alertview.TouchButton('OK');
end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");
  // Obtain the AlertView object
  var p = Mobile["Device"].Process("SampleApp");
  var alertview = p["Window"](2)["AlertView"]("Alert title");

  // Touch the "OK" button
  alertview["TouchButton"]("OK");
}

In Keyword Tests

To touch a button of an alert view control from keyword tests, use the On-Screen Action or Call Object Method operation to invoke the TouchButton method described above.

See Also

Working With iOS Alert View Controls
Working With Alert View Controls - Basic Concepts

Highlight search results