Determining the Number of Combo Box Items in Desktop Windows Applications

Applies to TestComplete 15.63, last modified on April 10, 2024

Note: To learn how to simulate user actions over combo box controls in web applications, see Working With Combo Box Controls in Web Applications.

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 working with a combo box control, you may need to determine the total number of items. If the tested application uses standard Win32 combo box controls, you can use various properties and methods provided by the Win32ComboBox object (this object is automatically associated with combo box controls during the test run).

Win32ComboBox provides a set of specific properties and methods that let you work with combo box controls. You can determine the total number of items a combo box contains via the wItemCount property. The following sample code demonstrates how you can do this:

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("~of");
  w = Sys.Process("NOTEPAD").Window("#32770", "Font", 1);
  ComboBox = w.Window("ComboBox", "", 5);
  
  // Post the total number of items to the log
  Log.Message("The total number of items:" + ComboBox.wItemCount);
}

Python

def Main():

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

  # Obtain a combo box object 
  p = Sys.Process("NOTEPAD")
  Sys.Keys("~of")
  w = Sys.Process("NOTEPAD").Window("#32770", "Font", 1)
  ComboBox = w.Window("ComboBox", "", 5)
  
  # Post the total number of items to the log
  Log.Message("The total number of items:" + str(ComboBox.wItemCount))

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 "~of"
  Set w = Sys.Process("NOTEPAD").Window("#32770", "Font", 1)
  Set ComboBox = w.Window("ComboBox", "", 5)
  
  ' Post the total number of items to the log
  Log.Message("The total number of items:" & ComboBox.wItemCount)
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('~of');
  w := Sys.Process('NOTEPAD').Window('#32770', 'Font', 1);
  ComboBox := w.Window('ComboBox', '', 5);
  
  // Post the total number of items to the log
  Log.Message('The total number of items:' + aqConvert.IntToStr(ComboBox.wItemCount));
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("~of");
  w = Sys["Process"]("NOTEPAD").Window("#32770", "Font", 1);
  ComboBox = w["Window"]("ComboBox", "", 5);
  
  // Post the total number of items to the log
  Log["Message"]("The total number of items:" + ComboBox.wItemCount);
}

See Also

Working With Combo Box Controls in Desktop Windows Applications
wItemCount Property (Combo Box Controls)
Working With Combo Box Controls in Web Applications

Highlight search results