Working With Multiline Edit Text Controls

Applies to TestComplete 12.60, last modified on September 17, 2018
Separating Lines of EditText

Mobile devices store contents of EditText controls as a set of strings, separated by line feed character. To access them, you need to change ListSeparator to the appropriate value. You can do it in the following way:  

JavaScript, JScript

aqString.ListSeparator = "\n";

Python

aqString.ListSeparator = "\n"

VBScript

aqString.ListSeparator = VbLf

DelphiScript

aqString.ListSeparator := #10;

C++Script, C#Script

aqString.ListSeparator = "\n";
Getting the Number of Lines in EditText

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

JavaScript, JScript

function Test()
{
  var p, Edit, Num;

  // Select the Android device
  Mobile.SetCurrent("MyDevice");

  // Obtain the EditText object and fill it with text
  p = Mobile.Device().Process("com.example.myapp");
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout3").EditText("edit5");
  Edit.SetText("This is line 1" + "\n" + "This is line 2" + "\n" + "This is line 3");
  
  // Set the list separator
  aqString.ListSeparator = "\n";
  
  // Get The number of lines
   Num = aqString.GetListLength(Edit.wText);
  Log.Message(Num);
}

Python

def Test():

  # Select the Android device
  Mobile.SetCurrent("MyDevice")

  # Obtain the EditText object and fill it with text 
  p = Mobile.Device().Process("com.example.myapp")
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout3").EditText("edit5")
  Edit.SetText("This is line 1" + "\n" + "This is line 2" + "\n" + "This is line 3")
  
  # Set the list separator
  aqString.ListSeparator = "\n"
  
  # Get The number of lines
  Num = aqString.GetListLength(Edit.wText)
  Log.Message(Num)

VBScript

Sub Test()
  Dim p, Edit, Num

  ' Select the Android device
  Call Mobile.SetCurrent("MyDevice")

  ' Obtain the EditText object and fill it with text
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Edit = p.RootLayout("").Layout("layoutTop").Layout("layout3").EditText("edit5")
  Call Edit.SetText("This is line 1" + VbLf + "This is line 2" + VbLf + "This is line 3")
  
  ' Set the list separator
  aqString.ListSeparator = VbLf
  
  ' Get The number of lines
  Num = aqString.GetListLength(Edit.wText)
  Call Log.Message(Num)
End Sub

DelphiScript

procedure Test();
var
  p, Edit, Num;
begin
  // Obtain the Android object
  Mobile.SetCurrent('MyDevice');

  // Obtain the EditText object and fill it with text
  p := Mobile.Device.Process('com.example.myapp');
  Edit := p.RootLayout('').Layout('layoutTop').Layout('layout3').EditText('edit5');
  Edit.SetText('This is line 1' + #10 + 'This is line 2' + #10 + 'This is line 3');
  
  // Set the list separator
  aqString.ListSeparator := #10;
  
  // Get The number of lines
  Num := aqString.GetListLength(Edit.wText);
  Log.Message(Num);
end;

C++Script, C#Script

function Test()
{
  var p, Edit, Num;

  // Select the Android device
  Mobile["SetCurrent"]("MyDevice")

  // Obtain the EditText object and fill it with text
  p = Mobile["Device"]["Process"]("com.example.myapp");
  Edit = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout3")["EditText"]("edit5");
  Edit["SetText"]("This is line 1" + "\n" + "This is line 2" + "\n" + "This is line 3");
  
  // Set the list separator
  aqString["ListSeparator"] = "\n";
  
  // Get The number of lines
  Num = aqString["GetListLength"](Edit.wText);
  Log["Message"](Num);
}

Getting a Single Line of EditText

To get a specific line of a multiline edit text control, use the GetListItem routine. The following example demonstrates how to get the specific line of the edit text control.

JavaScript, JScript

function Test()
{
  var p, Edit, Text, item;

  // Select the Android device
  Mobile.SetCurrent("MyDevice");

  // Obtain the EditText object and fill it with text
  p = Mobile.Device().Process("com.example.myapp");
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout3").EditText("edit5");
  Edit.SetText("This is line 1" + "\n" + "This is line 2" + "\n" + "This is line 3");
  
  // Set the list separator
  aqString.ListSeparator = "\n";
  
  // Get EditText object contents
  Text = Edit.wText;
  
  // Get the second line and post it to the log
  item = aqString.GetListItem(Text, 1);
  Log.Message(item);
}

Python

def Test():

  # Select the Android device
  Mobile.SetCurrent("MyDevice")

  # Obtain the EditText object and fill it with text 
  p = Mobile.Device().Process("com.example.myapp")
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout3").EditText("edit5")
  Edit.SetText("This is line 1" + "\n" + "This is line 2" + "\n" + "This is line 3")
  
  # Set the list separator
  aqString.ListSeparator = "\n"
  
  # Get EditText object contents
  Text = Edit.wText
  
  # Get the second line and post it to the log
  item = aqString.GetListItem(Text, 1)
  Log.Message(item)

VBScript

Sub Test()
  Dim p, Edit, Text, item

  ' Select the Android device
  Call Mobile.SetCurrent("MyDevice")

  ' Obtain the EditText object and fill it with text
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Edit = p.RootLayout("").Layout("layoutTop").Layout("layout3").EditText("edit5")
  Call Edit.SetText("This is line 1" + VbLf + "This is line 2" + VbLf + "This is line 3")
  
  ' Set the list separator
  aqString.ListSeparator = VbLf

  ' Get EditText object contents
  Text = Edit.wText
  
  ' Get the second line and post it to the log
  item = aqString.GetListItem(Text, 1)
  Log.Message(item)
End Sub

DelphiScript

procedure Test();
var
  p, Edit, Text, item : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');

  // Obtain the EditText object and fill it with text
  p := Mobile.Device.Process('com.example.myapp');
  Edit := p.RootLayout('').Layout('layoutTop').Layout('layout3').EditText('edit5');
  Edit.SetText('This is line 1' + #10 + 'This is line 2' + #10 + 'This is line 3');
  
  // Set the list separator
  aqString.ListSeparator := #10;
  
  // Get EditText object contents
  Text := Edit.wText;
  
  // Get the second line and post it to the log
  item := aqString.GetListItem(Text, 1);
  Log.Message(item);
end;

C++Script, C#Script

function Test()
{
  var p, Edit, Text, item;

  // Select the Android device
  Mobile["SetCurrent"]("MyDevice")

  // Obtain the EditText object and fill it with text
  p = Mobile["Device"]["Process"]("com.example.myapp");
  Edit = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout3")["EditText"]("edit5");
  Edit["SetText"]("This is line 1" + "\n" + "This is line 2" + "\n" + "This is line 3");
  
  // Set the list separator
  aqString["ListSeparator"] = "\n";
  
  // Get EditText object contents
  Text = Edit["wText"];
  
  // Get the second line and post it to the log
  item = aqString["GetListItem"](Text, 1);
  Log["Message"](item);
}

Simulating Actions From Keyword Tests

This topic explains how to work with the edit text control in scripts. You can use the described methods and properties in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.

See Also

Selecting Text Within the Edit Text Control
Working With Android Edit Text Controls
aqString.GetListLength Method
wText Property (Edit Controls)

Highlight search results