SetText Action (Specific to iOS Alert View)

Applies to TestComplete 14.72, last modified on December 24, 2020


The SetText action sets the textual contents of a control, that is, it replaces the existing contents with the specified text and then emulates touching the return key.



TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
Field [in]    Required    Variant    
Text [in]    Required    String    
Result None

Applies To

The method is applied to the following object:

View Mode

This method is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.


The method has the following parameters:


You can enter the field's index (from 0) or its caption.

The caption can contain asterisk (*) or question mark (?) wildcards or regular expressions. The asterisk corresponds to a string of any length (including an empty string), the question mark corresponds to any single character (including none). To specify more complicated parts of a caption, use regular expressions.

The caption can be case-sensitive or case-insensitive depending on the value of the Use case-sensitive parameters project setting.


The text to enter in the control. To enter multi-line text in a multi-line control, separate the lines by using new line characters or the corresponding constants.

Result Value



  • The SetText action fails when called for a disabled or read-only field.

  • To get a field’s text, use the wFieldText property. You can also use it to set text without posting a notification to the log.

  • To enter text in certain place within a field, to simulate keystrokes or character-by-character input, use the Keys action.


The following example sets the text of the first field in the alert view.

JavaScript, JScript

function Test()
  // Select the mobile device
  // Obtain the AlertView object
  var p = Mobile.Device().Process("SampleApp");
  var alertview = p.Window(2).AlertView("Alert title");
  alertview.SetText(0, "Example Text");


def Test():
  # Select the mobile device
  # Obtain the AlertView object 
  p = Mobile.Device().Process("SampleApp")
  alertview = p.Window(2).AlertView("Alert title")
  alertview.SetText(0, "Example Text")


Sub Test()
  Dim p, AView
  ' Select the mobile device
  ' Obtain the tableview object
  Set p = Mobile.Device.Process("SampleApp")
  Set AView = p.Window(2).AlertView("Alert title")
  Call AView.SetText(0, "Example Text")
End Sub


procedure Test();
  p, alertview;
  // Select the mobile device
  // Obtain the AlertView object
  p := Mobile.Device.Process('SampleApp');
  alertview := p.Window(2).AlertView('Alert title');
  alertview.SetText(0, 'Example Text');

C++Script, C#Script

function Test()
  // Select the mobile device
  // Obtain the AlertView object
  var p = Mobile["Device"].Process("SampleApp");
  var alertview = p["Window"](2)["AlertView"]("Alert title");
  alertview["SetText"](0, "Example Text");

See Also

Setting Alert View Field Text
iOS AlertView Support
wFieldText Property (Specific to iOS AlertView Object)

Highlight search results