Applies to TestComplete 14.20, last modified on September 11, 2019

While testing combo box controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

When testing a combo box control, you may need to work with its drop-down list. The Win32ComboBox object provides a set of specific properties and methods that you can use to perform certain actions over a drop-down list.

Before selecting an item in a drop-down list, you should open it. Thus, you may need to determine whether the drop-down list is open. Also, you may want your test to perform some actions depending on the state of the drop-down list. You can check the drop-down list's state via the wIsDropDownListOpened property that returns True if the drop-down list is open; otherwise, it returns False.

Note: wIsDropDownListOpened is always True if the tested combo box control is simple.

To open a drop-down list, you can either use the DropDown action provided by the Win32ComboBox object, or simulate keyboard shortcuts. Before opening a drop-down list by simulating keystrokes, you need to determine the interface mode of the combo box. You can determine the interface mode via the wExtendedUI property, which returns True if the tested control uses an extended user interface; otherwise, it returns False.

If the combo box uses a standard user interface, the F4 or Alt+Down shortcut opens or closes the list. If the combo box uses an extended user interface, the drop-down list is opened by pressing the Down key. You can close the drop-down list via the CloseUp action or by simulating the Enter or Esc key press.

After opening the drop-down list, you can navigate within it using the keyboard. You can simulate the Up and Down keystrokes that change the current selection in the list. For more information on how to simulate keystrokes, see Simulating Keystrokes.

The following example demonstrates how to work with a combo box's drop-down list.

JavaScript, JScript

function Main()
{
var p, w, ComboBox;

  // Run Notepad
  WshShell.Run("notepad.exe", SW_SHOWNORMAL);

  // Obtain a combo box object
  p = Sys.Process("NOTEPAD");
  Sys.Keys("~fo");
  w = p.Window("#32770", "Open", 1);
  ComboBox = w.Window("ComboBoxEx32", "", 1).Window("ComboBox", "", 1);
  
  // Determine the interface mode
  if (ComboBox.wExtendedUI)
    Log.Message("Extended")
  else
    Log.Message("Default");
  
  // Open the drop-down list if it is closed
  if (ComboBox.wIsDropDownListOpened == 0)
    ComboBox.DropDown();
  
  // Select an item and post it to log
  ComboBox.Keys("[Down][Down][Down]");
  ComboBox.CloseUp();
  
  // Post the index of the selected item to the log
  Log.Message(ComboBox.wSelectedItem);
}

Python

def Main():

  # Run Notepad
  WshShell.Run("notepad.exe", SW_SHOWNORMAL)

  # Obtain a combo box object 
  p = Sys.Process("NOTEPAD")
  Sys.Keys("~fo")
  w = p.Window("#32770", "Open", 1)
  ComboBox = w.Window("ComboBoxEx32", "", 1).Window("ComboBox", "", 1)
  
  # Determine the interface mode
  if (ComboBox.wExtendedUI):
    Log.Message("Extended")
  else:
    Log.Message("Default")
  
  # Open the drop-down list if it is closed 
  if (ComboBox.wIsDropDownListOpened == 0):
    ComboBox.DropDown()
  
  # Select an item and post it to log
  ComboBox.Keys("[Down][Down][Down]")
  ComboBox.CloseUp()
  
  # Post the index of the selected item to the log
  Log.Message(ComboBox.wSelectedItem)

VBScript

Sub Main
Dim p, w, ComboBox

  ' Run Notepad
  Call WshShell.Run("notepad.exe", SW_SHOWNORMAL)
  
  ' Obtain a combo box object
  Set p = Sys.Process("NOTEPAD")
  Sys.Keys "~fo"
  Set w = p.Window("#32770", "Open", 1)
  Set ComboBox = w.Window("ComboBoxEx32", "", 1).Window("ComboBox", "", 1)
  
  ' Determine the interface mode
  If (ComboBox.wExtendedUI = true) Then
    Log.Message("Extended")
  Else
    Log.Message("Default")
  End If
  
  ' Open the drop-down list if it is closed
  If ComboBox.wIsDropDownListOpened = 0 Then
    ComboBox.DropDown
  End If
  
  ' Select an item and post it to log
  ComboBox.Keys "[Down][Down][Down]"
  ComboBox.CloseUp
  
  ' Post the index of the selected item to the log
  Log.Message(ComboBox.wSelectedItem)
End Sub

DelphiScript

procedure Main();
var
p, w, ComboBox: OleVariant;
begin
  // Run Notepad
  WshShell.Run('notepad.exe', SW_SHOWNORMAL);
  
  // Obtain a combo box object
  p := Sys.Process('NOTEPAD');
  Sys.Keys('~fo');
  w := p.Window('#32770', 'Open', 1);
  ComboBox := w.Window('ComboBoxEx32', '', 1).Window('ComboBox', '', 1);
  
  // Determine the interface mode
  if (ComboBox.wExtendedUI)
  then
    Log.Message('Extended')
  else
    Log.Message('Default');
  
  // Open the drop-down list if it is closed
  if (ComboBox.wIsDropDownListOpened = 0)
  then
    ComboBox.DropDown();
  
  // Select an item and post it to log
  ComboBox.Keys('[Down][Down][Down]');
  ComboBox.CloseUp();
  
  // Post the index of the selected item to the log
  Log.Message(ComboBox.wSelectedItem);
end;

C++Script, C#Script

function Main()
{
var p, w, ComboBox;

  // Run Notepad
  WshShell["Run"]("notepad.exe", SW_SHOWNORMAL);
  
  // Obtain a combo box object
  p = Sys["Process"]("NOTEPAD");
  Sys.Keys("~fo");
  w = p.Window("#32770", "Open", 1);
  ComboBox = w["Window"]("ComboBoxEx32", "", 1).Window("ComboBox", "", 1);
    
  // Determine the interface mode
  if (ComboBox["wExtendedUI"])
    Log["Message"]("Extended")
  else 
    Log["Message"]("Default");

  // Open the drop-down list if it is closed
  if (ComboBox["wIsDropDownListOpened"] == 0)
    ComboBox["DropDown"]();
  
  // Select an item and post it to log
  ComboBox["Keys"]("[Down][Down][Down]");
  ComboBox["CloseUp"]();
  
  // Post the index of the selected item to the log
  Log["Message"](ComboBox["wSelectedItem"]);
}

See Also

Working With Combo Box Controls
wIsDropDownListOpened Property (Combo Box Controls)
wExtendedUI Property (Combo Box Controls)
DropDown Action (Combo Box Controls)
CloseUp Action (Combo Box Controls)
Simulating Keystrokes
Combo Box Types

Highlight search results