Join Wintertainment 2021 to share your stories, have fun, earn community badges, and more!

Working With Multiline Edit Controls

Applies to TestComplete 15.10, last modified on December 01, 2021

Text view controls in an iOS application can store multiple lines of text. Working with such controls is similar to working with single-line text edit controls. However, multiline controls have some specific features: you can perform operations on a set of strings. This topic describes the specifics of working with multiline edit controls.

Note: To work with multiple lines, you can use methods of the aqString scripting object.

Entering Multiline Text

Multiline text edit controls store their content as a set of strings separated by a line feed character. To enter several lines of text into a control, separate them by the appropriate character.

The following example demonstrates how to enter several text lines in a text view:

JavaScript, JScript

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

  // Obtain the TextView object and enter text in it
  var p = Mobile.Device().Process("SampleApp");
  var edit = p.Window(0).TextView();
  edit.SetText("I forgot you didn't like cats.\r\nNot like cats!! Would you like cats if you were me?");
}

Python

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

  # Obtain the TextView object and enter text in it
  p = Mobile.Device().Process("SampleApp")
  edit = p.Window(0).TextView()
  edit.SetText("I forgot you didn't like cats.\r\nNot like cats!! Would you like cats if you were me?")

VBScript

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

  ' Obtain the TextView object and enter text in it
  Set p = Mobile.Device.Process("SampleApp")
  Set edit = p.Window(0).TextView
  edit.SetText("I forgot you didn't like cats." & vbCrLf & "Not like cats!! Would you like cats if you were me?")
End Sub

DelphiScript

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

  // Obtain the TextView object and enter text in it
  p := Mobile.Device.Process('SampleApp');
  edit := p.Window(0).TextView;
  edit.SetText('I forgot you didn''t like cats.' + #13#10 +'Not like cats!! Would you like cats if you were me?');
end;

C++Script, C#Script

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

  // Obtain the TextView object and enter text in it
  var p = Mobile["Device"]["Process"]("SampleApp");
  var edit = p["Window"](0)["TextView"]();
  edit["SetText"]("I forgot you didn't like cats.\r\nNot like cats!! Would you like cats if you were me?");
}

Getting the Number of Text Lines

To determine the number of lines in a multiline edit control, use the aqString.GetListLength method. The following example demonstrates how to obtain the number of lines in the text view control:

JavaScript, JScript

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

  // Obtain the TextView object and fill it with text
  var p = Mobile.Device().Process("SampleApp");
  var edit = p.Window(0).TextView();
  edit.SetText("Line1\r\nLine2\r\nLine3");

  // Specify the list separator
  aqString.ListSeparator = "\r\n";

  // Get the number of lines
  var count = aqString.GetListLength(edit.wText);
  Log.Message(count);
}

Python

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

  # Obtain the TextView object and fill it with text
  p = Mobile.Device().Process("SampleApp")
  edit = p.Window(0).TextView()
  edit.SetText("Line1\r\nLine2\r\nLine3")

  # Specify the list separator
  aqString.ListSeparator = "\r\n"

  # Get the number of lines
  count = aqString.GetListLength(edit.wText)
  Log.Message(count)

VBScript

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

  ' Obtain the TextView object and fill it with text
  Set p = Mobile.Device.Process("SampleApp")
  Set edit = p.Window(0).TextView
  edit.SetText("Line1" & vbCrLf & "Line2" & vbCrLf & "Line3")

  ' Specify the list separator
  aqString.ListSeparator = vbCrLf

  ' Get the number of lines
  count = aqString.GetListLength(edit.wText)
  Log.Message(count)
End Sub

DelphiScript

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

  // Obtain the TextView object and fill it with text
  p := Mobile.Device.Process('SampleApp');
  edit := p.Window(0).TextView();
  edit.SetText('Line1' + #13#10 + 'Line2' + #13#10 + 'Line3');

  // Specify the list separator
  aqString.ListSeparator := #13#10;

  // Get the number of lines
  count := aqString.GetListLength(edit.wText);
  Log.Message(count);
end;

C++Script, C#Script

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

  // Obtain the TextView object and fill it with text
  var p = Mobile["Device"]["Process"]("SampleApp");
  var edit = p["Window"](0)["TextView"]();
  edit["SetText"]("Line1\r\nLine2\r\nLine3");

  // Specify the list separator
  aqString["ListSeparator"] = "\r\n";

  // Get the number of lines
  var count = aqString["GetListLength"](edit.wText);
  Log["Message"](count);
}
Note: To specify a set of characters that delimit strings in the multiline text, use the aqString.ListSeparator property.

Getting a Single Line of Text

To get a specific line of the multiline edit control, use the aqString.GetListItem method.

The following example demonstrates how to get the specific line of the text view control:

JavaScript, JScript

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

  // Obtain the TextView object and fill it with text
  var p = Mobile.Device().Process("SampleApp");
  var edit = p.Window(0).TextView();
  edit.SetText("Line1\r\nLine2\r\nLine3");

  // Specify the list separator
  aqString.ListSeparator = "\r\n";

  // Get the TextView object's text content
  var text = edit.wText;

  // Get the second line and post it to the log
  var line = aqString.GetListItem(text, 1);
  Log.Message(line);
}

Python

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

  # Obtain the TextView object and fill it with text 
  p = Mobile.Device().Process("SampleApp")
  edit = p.Window(0).TextView()
  edit.SetText("Line1\r\nLine2\r\nLine3")

  # Specify the list separator 
  aqString.ListSeparator = "\r\n"

  # Get the TextView object's text content 
  text = edit.wText

  # Get the second line and post it to the log 
  line = aqString.GetListItem(text, 1)
  Log.Message(line)

VBScript

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

  ' Obtain the TextView object and fill it with text
  Set p = Mobile.Device.Process("SampleApp")
  Set edit = p.Window(0).TextView
  edit.SetText("Line1" & vbCrLf & "Line2" & vbCrLf & "Line3")

  ' Specify the list separator
  aqString.ListSeparator = vbCrLf

  ' Get the TextView object's text content
  text = edit.wText

  ' Get the second line and post it to the log
  line = aqString.GetListItem(text, 1)
  Log.Message(line)
End Sub

DelphiScript

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

  // Obtain the TextView object and fill it with text
  p := Mobile.Device.Process('SampleApp');
  edit := p.Window(0).TextView();
  edit.SetText('Line1' + #13#10 + 'Line2' + #13#10 + 'Line3');

  // Specify the list separator
  aqString.ListSeparator := #13#10;

  // Get the TextView object's text content
  text := edit.wText;

  // Get the second line and post it to the log
  line := aqString.GetListItem(text, 1);
  Log.Message(line);
end;

C++Script, C#Script

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

  // Obtain the TextView object and fill it with text
  var p = Mobile["Device"]["Process"]("SampleApp");
  var edit = p["Window"](0)["TextView"]();
  edit["SetText"]("Line1\r\nLine2\r\nLine3");

  // Specify the list separator
  aqString["ListSeparator"] = "\r\n";

  // Get the TextView object's text content
  var text = edit["wText"];

  // Get the second line and post it to the log
  var line = aqString["GetListItem"](text, 1);
  Log["Message"](line);
}

Simulating Actions From Keyword Tests

To work with multiline edit controls in iOS applications from keyword tests, you can call the described methods and properties. To do this, use the On-Screen Action or the Call Object Method operation. For more information, see Calling Object Methods and Getting and Setting Object Property Values.

See Also

Working With iOS Text Edit Controls
Getting an Edit Control's Text
Entering Text in an Edit Control
iOS TextView Support
Testing iOS Applications (Legacy)

Highlight search results