Entering Text into an Edit Text Control

Applies to TestComplete 15.69, last modified on November 13, 2024
Entering Text in EditText Control
Simulating SetText Action

To specify the text of an EditText control, use the SetText action or the wText property. If you use the SetText action, the entry about the performed operation will be added to the test log. The following example sets the text of the edit text control:

JavaScript, JScript

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

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

  // Obtain the EditText object
  p = Mobile.Device().Process("com.example.myapp");
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1");
  
  // Fill it with text
  Edit.SetText("But who is to give the prizes?");
}

Python

def Test():

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

  # Obtain the EditText object
  p = Mobile.Device().Process("com.example.myapp")
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1")
  
  # Fill it with text 
  Edit.SetText("But who is to give the prizes?")

VBScript

Sub Test()
  Dim p, Edit, Text

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

  ' Obtain the EditText object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1")
  
  ' Fill it with text
  Call Edit.SetText("But who is to give the prizes?")
End Sub

DelphiScript

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

  // Obtain the EditText object
  p := Mobile.Device.Process('com.example.myapp');
  Edit := p.RootLayout('').Layout('layoutTop').Layout('layout1').EditText('edit1');
  
  // Fill it with text
  Edit.SetText('But who is to give the prizes?');
end;

C++Script, C#Script

function Test()
{
  var p, Edit;

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

  // Obtain the EditText object
  p = Mobile["Device"]["Process"]("com.example.myapp");
  Edit = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1")["EditText"]("edit1");
  
  // Fill it with text
  Edit["SetText"]("But who is to give the prizes?");
}

Simulating Keys Action

To add new text to an edit text control, “type” text using the Keys action. This action allows you to add text in the control without changing the rest of it. The following example sends text to the EditText control:

JavaScript, JScript

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

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

  // Obtain the EditText object
  p = Mobile.Device().Process("com.example.myapp");
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1");
  
  // Fill it with text
  Edit.Keys("But who is to give the prizes?");
}

Python

def Test():

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

  # Obtain the EditText object
  p = Mobile.Device().Process("com.example.myapp")
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1")
  
  # Fill it with text 
  Edit.Keys("But who is to give the prizes?")

VBScript

Sub Test()
  Dim p, Edit, Text

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

  ' Obtain the EditText object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1")
  
  ' Fill it with text
  Call Edit.Keys("But who is to give the prizes?")
End Sub

DelphiScript

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

  // Obtain the EditText object
  p := Mobile.Device.Process('com.example.myapp');
  Edit := p.RootLayout('').Layout('layoutTop').Layout('layout1').EditText('edit1');
  
  // Fill it with text
  Edit.Keys('But who is to give the prizes?');
end;

C++Script, C#Script

function Test()
{
  var p, Edit;

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

  // Obtain the EditText object
  p = Mobile["Device"]["Process"]("com.example.myapp");
  Edit = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1")["EditText"]("edit1");
  
  // Fill it with 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 an Edit Text Control topic.

Deleting Text From TextBox Controls
Simulating Keystrokes

To delete symbols, simulate Delete keystrokes using the PressButton action. This deletes one symbol backwards per simulated press. Here is an example:

JavaScript, JScript

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

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

  // Obtain the EditText object
  p = Mobile.Device().Process("com.example.myapp");
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1");
  
  // Fill it with text
  Edit.Keys("But who is to give the prizes??");
  
  // Delete the last symbol
  Mobile.Device().PressButton(mbkDel);
}

Python

def Test():

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

  # Obtain the EditText object
  p = Mobile.Device().Process("com.example.myapp")
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1")
  
  # Fill it with text 
  Edit.Keys("But who is to give the prizes??")
  
  # Delete the last symbol
  Mobile.Device().PressButton(mbkDel)

VBScript

Sub Test()
  Dim p, Edit, Text

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

  ' Obtain the EditText object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1")
  
  ' Fill it with text
  Call Edit.Keys("But who is to give the prizes??")
  
  ' Delete the last symbol
  Call Mobile.Device.PressButton(mbkDel)
End Sub

DelphiScript

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

  // Obtain the EditText object
  p := Mobile.Device.Process('com.example.myapp');
  Edit := p.RootLayout('').Layout('layoutTop').Layout('layout1').EditText('edit1');
  
  // Fill it with text
  Edit.Keys('But who is to give the prizes??');
  
  // Delete the last symbol
  Mobile.Device.PressButton(mbkDel);
end;

C++Script, C#Script

function Test()
{
  var p, Edit;

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

  // Obtain the EditText object
  p = Mobile["Device"]["Process"]("com.example.myapp");
  Edit = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1")["EditText"]("edit1");
  
  // Fill it with text
  Edit["Keys"]("But who is to give the prizes??");
  
  // Delete the last symbol
  Mobile["Device"]["PressButton"](mbkDel);
}

Simulating SetText Action

To delete all text in a control, use the SetText action with an empty string as a parameter, or assign an empty value to the wText property. The example below demonstrates how to perform this operation:

JavaScript, JScript

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

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

  // Obtain the EditText object
  p = Mobile.Device().Process("com.example.myapp");
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1");
  
  // Fill it with text
  Edit.Keys("But who is to give the prizes??");
  
  // Delete the text
  Edit.SetText("");
}

Python

def Test():

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

  # Obtain the EditText object
  p = Mobile.Device().Process("com.example.myapp")
  Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1")
  
  # Fill it with text 
  Edit.Keys("But who is to give the prizes??")
  
  # Delete the text
  Edit.SetText("")

VBScript

Sub Test()
  Dim p, Edit, Text

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

  ' Obtain the EditText object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Edit = p.RootLayout("").Layout("layoutTop").Layout("layout1").EditText("edit1")
  
  ' Fill it with text
  Call Edit.Keys("But who is to give the prizes??")
  
  ' Delete the text
  Call Edit.SetText("")
End Sub

DelphiScript

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

  // Obtain the EditText object
  p := Mobile.Device.Process('com.example.myapp');
  Edit := p.RootLayout('').Layout('layoutTop').Layout('layout1').EditText('edit1');
  
  // Fill it with text
  Edit.Keys('But who is to give the prizes??');
  
  // Delete the text
  Edit.SetText('');
end;

C++Script, C#Script

function Test()
{
  var p, Edit;

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

  // Obtain the EditText object
  p = Mobile["Device"]["Process"]("com.example.myapp");
  Edit = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1")["EditText"]("edit1");
  
  // Fill it with text
  Edit["Keys"]("But who is to give the prizes??");
  
  // Delete the text
  Edit["SetText"]("");
}

Cutting the Text

You can the Cut item of the Text selection’s context menu. For more information on using the Cut item, see Copying and Pasting Text in an Edit Text Control

Simulating Actions From Keyword Tests

This topic explains how to enter text in 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
Simulating Text Input on Android Devices (Legacy)
Copying and Pasting Text in an Edit Text Control
Selecting Text Within the Edit Text Control
wText Property (Mobile Edit Controls)
SetText Action (Mobile Controls)

Highlight search results