Getting Alert View Button and Field Text

Applies to TestComplete 15.70, last modified on December 17, 2024

You can address alert view buttons and fields by their indexes or captions. Using captions is usually better, as it makes your tests more readable. However, the captions may change during the application run. You can verify that a button or field contains the correct text or save the text to a variable for future use. This topic explains how you can obtain the text of a button or field.

Getting Text From Scripts

The AlertView object provides wButtonText and wFieldText properties that return the text of the button or field respectively. You need to specify the item by its index. The following example obtains the text of the first button in the alert view,  saves it to the variable and posts it 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");

  // Add the AlertView button text to the variable
  var buttontext = alertview.wButtonText(0);

  // Post the text to the log
  Log.Message(buttontext);
}

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

  # Add the AlertView button text to the variable
  buttontext = alertview.wButtonText[0]

  # Post the text to the log
  Log.Message(buttontext)

VBScript

Sub Test()
  Dim p, AView, buttontext
  ' 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")

  ' Add the AlertView button text to the variable
  buttontext = AView.wButtonText(0)

  ' Post the text to the log
  Log.Message(buttontext)
End Sub

DelphiScript

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

  // Add the AlertView button text to the variable
  buttontext := alertview.wButtonText(0);

  // Post the text to the log
  Log.Message(buttontext);
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");

  // Add the AlertView button text to the variable
  var buttontext = alertview.wButtonText(0);

  // Post the text to the log
  Log.Message(buttontext);
}

Getting Text From Keyword Tests

To get a button or field text of an alert view 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
wButtonText Property (Specific to iOS AlertView Object)
wFieldText Property (Specific to iOS AlertView Object)

Highlight search results