Getting an Edit Control's Text

Applies to TestComplete 14.40, last modified on April 22, 2021

While testing edit controls in iOS applications, you use special properties and methods of the corresponding test object (iOS TextField or iOS TextView) to perform certain actions and obtain data stored in the controls. This topic describes how to get the text displayed in an iOS edit control.

Getting Text

To get the text of an edit control in an iOS application, use the wText property. This property returns the entire text of the edit control. The following example demonstrates how you can obtain an edit control’s text:

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

  // Get the text of the control and post it to the test log
  var text = edit.wText;
  Log.Message(text);
}

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

  # Get the text of the control and post it to the test log
  text = edit.wText
  Log.Message(text)

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

  ' Get the text of the control and post it to the test log
  text = edit.wText
  Log.Message text
End Sub

DelphiScript

procedure Test();
var p, edit, text;
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?');

  // Get the text of the control and post it to the test log
  text := edit.wText;
  Log.Message(text);
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?");

  // Get the text of the control and post it to the test log
  var text = edit["wText"];
  Log["Message"](text);
}

Getting a Portion of Text

To get part of the text displayed in an edit control in an iOS application, you can select the needed text and then retrieve it using the wSelection property (for more information, see the Selecting Text Within an Edit Control topic).

Simulating Actions in Keyword Tests

To obtain the text displayed in an edit control in keyword tests, call the wText property described above by using the On-Screen Action or Call Object Method operation.

See Also

Working With iOS Text Edit Controls
Working With Multiline 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

Highlight search results