Getting the Number of Alert View's Buttons and Fields

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

An alert view control may include multiple buttons or fields. You may need to work with multiple items at once, for example, to check the text of all alert view buttons. To do this, use the wButtonCount or wFieldCount property of the iOS AlertView object. These properties return the number of the corresponding items in the control. They are available both in scripts and in keyword tests.

In Script Code

The following code snippet iterates through the buttons of an alert view control and posts the buttons’ captions to the log:

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");

  // Post the text of all buttons to the log
  for (var i=0; i<alertview.wButtonCount;i++)
    Log.Message(alertview.wButtonText(i));
}

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")

  # Post the text of all buttons to the log
  for i in range(0, alertview.wButtonCount-1):
    Log.Message(alertview.wButtonText[i])

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")

  ' Post the text of all buttons to the log
  For i = 0 To AView.wButtonCount-1
    Log.Message(AView.wButtonText(i))
  Next
End Sub

DelphiScript

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

  // Post the text of all buttons to the log
  for i := 0 to alertview.wButtonCount-1 do
    Log.Message(alertview.wButtonText(i));
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");

  // Post the text of all buttons to the log
  for (var i=0; i<alertview["wButtonCount"];i++)
    Log["Message"](alertview["wButtonText"](i));
}

In Keyword Tests

To obtain the number of buttons and fields of an alert view control 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 Alert View Controls
iOS AlertView Support
wButtonCount Property (Specific to iOS AlertView Object)
wFieldCount Property (Specific to iOS AlertView Object)

Highlight search results