SetText Action (Specific to iOS Alert View)

Applies to TestComplete 15.20, last modified on January 19, 2022
This method is available in legacy mobile tests that work with devices connected to the local computer. To learn how to simulate user actions in newer cloud-compatible mobile tests, see the Simulating user actions in tests section.

Description

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.

Declaration

TestObj.SetText(Field, Text)

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.

Parameters

The method has the following parameters:

Field

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.

Text

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

None.

Remarks

  • 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.

Example

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

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");
  
  alertview.SetText(0, "Example Text");
}

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")
  
  alertview.SetText(0, "Example Text")

VBScript

Sub Test()
  Dim p, AView
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' 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

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');
  
  alertview.SetText(0, 'Example Text');
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");
  
  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