Getting the Edit Text Control's Text

Applies to TestComplete 14.40, last modified on April 22, 2021
Getting wText Property

To get the whole text of an EditText control, use the wText property. This property returns full text of the edit text control. In this case, it does not matter whether the text is selected or not. The following example demonstrates how you can obtain the edit text control’s text:

JavaScript, JScript

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

  // 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("layout1").EditText("edit1");
  Edit.SetText("But who is to give the prizes?");
  
  // Get the text of the control
  Text = Edit.wText;
  
  // Post the text to the log
  Log.Message(Text);
}

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("layout1").EditText("edit1")
  Edit.SetText("But who is to give the prizes?")
  
  # Get the text of the control 
  Text = Edit.wText
  
  # Post the text to the log
  Log.Message(Text)

VBScript

Sub Test()
  Dim p, Edit, Text

  ' 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("layout1").EditText("edit1")
  Call Edit.SetText("But who is to give the prizes?")
  
  ' Get the text of the control
  Text = Edit.wText
  
  ' Post the text to the log
  Log.Message(Text)
End Sub

DelphiScript

procedure Test();
var
  p, Edit, Text : 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('layout1').EditText('edit1');
  Edit.SetText('But who is to give the prizes?');
  
  // Get the text of the control
  Text := Edit.wText;
  
  // Post the text to the log
  Log.Message(Text);
end;

C++Script, C#Script

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

  // 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"]("layout1")["EditText"]("edit1");
  Edit["SetText"]("But who is to give the prizes?");
  
  // Get the text of the control
  Text = Edit["wText"];
  
  // Post the text to the log
  Log["Message"](Text);
}

Getting Part of Text

To get a part of text from an EditText control, first select the needed text, then retrieve it using the wSelection property (for more details, see the Copying and Pasting Text in an Edit Text Control topic).

Simulating Actions From Keyword Tests

This topic explains how to obtain the text of 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

Working With Android Edit Text Controls
Copying and Pasting Text in an Edit Text Control
Entering Text into an Edit Text Control
Selecting Text Within the Edit Text Control
wText Property (Mobile Edit Controls)

Highlight search results