Setting Alert View Field Text

Applies to TestComplete 15.62, last modified on March 19, 2024

Alert view controls are also used as a means to provide a user with an input field, for example, for specifying a user name or password. To "enter" text in a field, use the SetText action or the wFieldText property. The action simulates text input and pressing Enter in a field. The property changes the field’s text without activating the field. You specify the field either by its index (starting from 0) or by its caption. To learn more about getting a field caption, see Getting Alert View Button and Field Text. Both SetText and wFieldText are available in script code and in keyword tests.

In Script Code

The following code snippet sets text in the first field in an alert view control:

JavaScript

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

  // Set the AlertView's text
  alertview.SetText(0, "Example Text");
  alertview.$set("wFieldText", 0, "Second field");
}

JScript

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

  // Set the AlertView's text
  alertview.SetText(0, "Example Text");
  alertview.wFieldText(0) = "Second field";
}

Python

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

  # Set the AlertView's text
  alertview.SetText(0, "Example Text")
  alertview.wFieldText[0] = "Second field"

VBScript

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

  ' Set the AlertView's text
  Call AView.SetText(0, "Example Text")
  AView.wFieldText(1) = "Second field"
End Sub

DelphiScript

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

  // Set the AlertView's text
  alertview.SetText(0, 'Example Text');
  alertview.wFieldText(0) := 'Second field';
end;

C++Script, C#Script

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

  // Set the AlertView's text
  alertview["SetText"](0, "Example Text");
  alertview["wFieldText"](0) = "Second field";
}

In Keyword Tests

To set the text of an alert view field from keyword tests, use the On-Screen Action or Call Object Method operation to access the properties described above. See Getting and Setting Object Property Values.

See Also

Working With iOS Alert View Controls
Getting Alert View Button and Field Text

Highlight search results