SetText Action (Edit and Combo Box Controls)

Applies to TestComplete 15.64, last modified on June 12, 2024
This method is not supported in web tests (including cross-platform web tests) that use XPath expressions and CSS selectors to locate web elements. This method can be only used in tests that locate web objects by using internal identification properties provided by TestComplete.


The SetText action sets the contents of a control, that is, replaces the previous contents with the specified text.

To get a control’s text, use the wText (for edit controls) or the wText (for combo box controls) property.



TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
Text [in]    Required    String    
Result None

Applies To

The method is applied to the following objects:

View Mode

This method is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.


The method has the following parameter:


The text to enter in the control. To enter multi-line text in a multi-line control, separate the lines by using new line characters or the appropriate constants (see the example at the end of the topic).

Result Value



  • By default, TestComplete uses the SetText method to record text input in password edit boxes and stores password values as project password variables:

    JavaScript, JScript








    C++Script, C#Script


    If your passwords are recorded as text stings and are not masked in tests, make sure the Tools > Options > Engines > Recording > Record text input into simple editors as option is set to SetText (the default value).

  • The SetText action does not activate the application window that contains the control, though it moves the insertion point to the beginning of the control’s text. Unlike the wText (for edit controls) and the wText (for combo box controls) properties, SetText fails when it is applied to a disabled or read-only control.

  • The SetText action works differently for web and desktop objects. For test objects in desktop applications, the action raises only text change events and does not raise keystroke events. For test objects on web pages, the action fires the onchange event (a “text change” event), and “keystroke” events like keyup, input and keydown that may trigger keyboard-related scripts (for example, autocompletion popups). Anyway, if the expected event does not occur, try using the Keys action.

  • Web Text Box, jQuery UI Autocomplete, YUI 2 AutoComplete, YUI 3 AutoComplete: The method moves the insertion point to the end of the control’s text.

  • To enter text in a certain place within a control, use the Keys action to set the insertion point position and to type the desired text. You can find an example in the Setting Insertion Point in an Edit Control in Desktop Windows Applications topic.

  • To simulate certain keystrokes in a control (such as Del, Home, Ctrl+C and so on) or character-by-character input, use the Keys action as well.

  • To control whether the SetText action should be used to record text input into edit controls, use the Record text input into simple editors as option.


The following script demonstrates how you can enter single-line and multi-line text into Notepad. (Notepad must be running before you run this script).

JavaScript, JScript

function Test()
  var edit = Sys.Process("notepad").Window("Notepad").Window("Edit");
  edit.SetText("The quick brown fox");
  edit.SetText("The quick brown fox\r\n" +
               "jumps over\r\n" +
               "the lazy dog");


def Test():
  edit = Sys.Process("notepad").Window("Notepad").Window("Edit")
  edit.SetText("The quick brown fox")
  edit.SetText("The quick brown fox\r\n" +\
               "jumps over\r\n" +\
               "the lazy dog")


Sub Test
  Dim edit
  Set edit = Sys.Process("notepad").Window("Notepad").Window("Edit")
  edit.SetText "The quick brown fox"
  aqUtils.Delay 2000
  edit.SetText "The quick brown fox" & vbNewLine & _
               "jumps over" & vbNewLine & _
               "the lazy dog"
End Sub


procedure Test;
var edit;
  edit := Sys.Process('notepad').Window('Notepad').Window('Edit');
  edit.SetText('The quick brown fox');
  edit.SetText('The quick brown fox' + #13#10 +
               'jumps over' + #13#10 +
               'the lazy dog');

C++Script, C#Script

function Test()
  var edit = Sys["Process"]("notepad")["Window"]("Notepad")["Window"]("Edit");
  edit["SetText"]("The quick brown fox");
  edit["SetText"]("The quick brown fox\r\n" +
                  "jumps over\r\n" +
                  "the lazy dog");

See Also

wText Property (Edit Controls)
Keys Action
Entering Text into an Edit Control in Desktop Windows Applications

Highlight search results