Entering Text in an Edit Control

Applies to TestComplete 15.69, last modified on November 13, 2024

Testing edit controls often implies modifying the text displayed in the controls. This topic describes several approaches you can use to enter text in an edit control in an iOS application or to clear text in a control.

Entering Text in Edit Controls

Calling the SetText Method and the wText Property

To enter text in an edit control in an iOS application, use the SetText method or the wText property of the test object TestComplete associates with the control (iOS TextField or iOS TextView). If you use the SetText method, TestComplete posts information about the performed operation to the test log.

The following example enters text in an edit control:

JavaScript, JScript

function Test()
{
  // Select the iOS device
  Mobile.SetCurrent("iPhone");

  // Obtain the iOS TextField object and enter text in it
  var p = Mobile.Device().Process("SampleApp");
  var edit = p.Window(0).TextField();
  edit.SetText("But who is to give the prizes?");
}

Python

def Test():
  # Select the iOS device
  Mobile.SetCurrent("iPhone")

  # Obtain the iOS TextField object and enter text in it
  p = Mobile.Device().Process("SampleApp")
  edit = p.Window(0).TextField()
  edit.SetText("But who is to give the prizes?")

VBScript

Sub Test
  ' Select the iOS device
  Mobile.SetCurrent("iPhone")

  ' Obtain the iOS TextField object and enter text in it
  Set p = Mobile.Device.Process("SampleApp")
  Set edit = p.Window(0).TextField
  edit.SetText "But who is to give the prizes?"
End Sub

DelphiScript

procedure Test();
var p, edit;
begin
  // Select the iOS device
  Mobile.SetCurrent('iPhone');

  // Obtain the iOS TextField object and enter text in it
  p := Mobile.Device.Process('SampleApp');
  edit := p.Window(0).TextField();
  edit.SetText('But who is to give the prizes?');
end;

C++Script, C#Script

function Test()
{
  // Select the iOS device
  Mobile["SetCurrent"]("iPhone");

  // Obtain the iOS TextField object and enter text in it
  var p = Mobile["Device"]["Process"]("SampleApp");
  var edit = p["Window"](0)["TextField"]();
  edit["SetText"]("But who is to give the prizes?");
}
Simulating Keystrokes

To enter new text in an edit control, “type” the text using the Keys action. This action allows you to enter new text in the control without changing the initial text. The following example enters text in an edit control:

JavaScript, JScript

function Test()
{
  // Select the iOS device
  Mobile.SetCurrent("iPhone");

  // Obtain the iOS TextField object
  var p = Mobile.Device().Process("SampleApp");
  var edit = p.Window(0).TextField();

  // Type text
  edit.Keys("But who is to give the prizes?");
}

Python

def Test():
  # Select the iOS device
  Mobile.SetCurrent("iPhone")

  # Obtain the iOS TextField object
  p = Mobile.Device().Process("SampleApp")
  edit = p.Window(0).TextField()

  # Type text
  edit.Keys("But who is to give the prizes?")

VBScript

Sub Test
  ' Select the iOS device
  Mobile.SetCurrent("iPhone")

  ' Obtain the iOS TextField object
  Set p = Mobile.Device.Process("SampleApp")
  Set edit = p.Window(0).TextField

  ' Type text
  edit.Keys "But who is to give the prizes?"
End Sub

DelphiScript

procedure Test();
var p, edit;
begin
  // Select the iOS device
  Mobile.SetCurrent('iPhone');

  // Obtain the iOS TextField object
  p := Mobile.Device.Process('SampleApp');
  edit := p.Window(0).TextField();

  // Type text
  edit.Keys('But who is to give the prizes?');
end;

C++Script, C#Script

function Test()
{
  // Select the iOS device
  Mobile["SetCurrent"]("iPhone");

  // Obtain the iOS TextField object
  var p = Mobile["Device"]["Process"]("SampleApp");
  var edit = p["Window"](0)["TextField"]();

  // Type text
  edit["Keys"]("But who is to give the prizes?");
}
Pasting Text

You can paste text from the clipboard. This approach is described in the Copying and Pasting Text in Edit Controls topic.

Clearing Text

Calling the SetText Method and the wText Property

To delete the whole text in a control, call the SetText method of the corresponding iOS TextField test object with an empty string as a parameter, or assign an empty value to its wText property. In this case, the whole text displayed in the edit control is deleted. The example below demonstrates how to perform this operation:

JavaScript, JScript

function Test()
{
  // Select the iOS device
  Mobile.SetCurrent("iPhone");

  // Obtain the iOS TextField object
  var p = Mobile.Device().Process("SampleApp");
  var edit = p.Window(0).TextField();

  // Clear the text
  edit.SetText("");
}

Python

def Test()
  # Select the iOS device
  Mobile.SetCurrent("iPhone")

  # Obtain the iOS TextField object
  p = Mobile.Device().Process("SampleApp")
  edit = p.Window(0).TextField()

  # Clear the text
  edit.SetText("")

VBScript

Sub Test
  ' Select the iOS device
  Mobile.SetCurrent "iPhone"

  ' Obtain the iOS TextField object
  Set p = Mobile.Device.Process("SampleApp")
  Set edit = p.Window(0).TextField

  ' Clear the text
  edit.SetText ""
End Sub

DelphiScript

procedure Test();
var p, edit;
begin
  // Select the iOS device
  Mobile.SetCurrent('iPhone');

  // Obtain the iOS TextField object
  p := Mobile.Device.Process('SampleApp');
  edit := p.Window(0).TextField();

  // Clear the text
  edit.SetText('');
end;

C++Script, C#Script

function Test()
{
  // Select the iOS device
  Mobile["SetCurrent"]("iPhone");

  // Obtain the iOS TextField object
  var p = Mobile["Device"]["Process"]("SampleApp");
  var edit = p["Window"](0)["TextField"]();

  // Clear the text
  edit["SetText"]("");
}
Cutting Text

You can use the Cut and Delete commands of an edit control’s context menu. For more information, see Copying and Pasting Text in Edit Controls.

Calling Native Methods

You can use an edit control’s native properties and methods exposed by TestComplete to clear the text displayed in the edit control.

The example below demonstrates how to use the native clearText method of an edit control to do this:

JavaScript, JScript

function Test()
{
  // Select the iOS device
  Mobile.SetCurrent("iPhone");

  // Obtain the iOS TextField object
  var p = Mobile.Device().Process("SampleApp");
  var edit = p.Window(0).TextField();

  // Clear the text
  edit.clearText();
}

Python

def Test():
  # Select the iOS device
  Mobile.SetCurrent("iPhone")

  # Obtain the iOS TextField object
  p = Mobile.Device().Process("SampleApp")
  edit = p.Window(0).TextField()

  # Clear the text
  edit.clearText()

VBScript

Sub Test
  ' Select the iOS device
  Mobile.SetCurrent("iPhone")

  ' Obtain the iOS TextField object
  Set p = Mobile.Device.Process("SampleApp")
  Set edit = p.Window(0).TextField

  ' Clear the text
  edit.clearText
End Sub

DelphiScript

procedure Test();
var p, edit;
begin
  // Select the iOS device
  Mobile.SetCurrent('iPhone');

  // Obtain the iOS TextField object
  p := Mobile.Device.Process('SampleApp');
  edit := p.Window(0).TextField();

  // Clear the text
  edit.clearText();
end;

C++Script, C#Script

function Test()
{
  // Select the iOS device
  Mobile["SetCurrent"]("iPhone");

  // Obtain the iOS TextField object
  var p = Mobile["Device"]["Process"]("SampleApp");
  var edit = p["Window"](0)["TextField"]();

  // Clear the text
  edit["clearText"]();
}

Simulating Actions in Keyword Tests

To modify text displayed in the edit control in your iOS application 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 Text Edit Controls
iOS TextField Support
Selecting Text Within an Edit Control
Copying and Pasting Text in Edit Controls
wText Property (Mobile Edit Controls)
SetText Action (Mobile Controls)
Testing iOS Applications (Legacy)

Highlight search results