Getting Combo Box Items' Images in Desktop Windows Applications

Applies to TestComplete 15.40, last modified on July 05, 2022

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

Combo box controls can display images next to items. There are two types of images that can be associated with an item: default images, which are displayed when an item is not selected, and selected images, which are displayed when an item is selected.

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.

The Win32ComboBox object provides two specific properties that let you work with the images of combo box items:

  • wItemImage returns the Picture object that corresponds to the item’s default image.
  • wItemSelectedImage returns the Picture object that corresponds to the item’s selected image.
Note: These properties are only used with ComboBoxEx controls that combine the functionality of a combo box with support for item images. If the specified item of ComboBoxEx does not have an image, or if the tested control is the ComboBox control, the above-mentioned properties return an empty object.

After obtaining an image, you can process it the same way you process ordinary images. TestComplete provides a set of different methods that allow you to post the obtained image to the log, save it to a file, compare it with another image and so on. See the Picture object description to get information on available methods. The following example demonstrates how to obtain an item's default image and post it to the log:

JavaScript

function main()
{
  var p, w, i, ComboBoxEx, ItemNumber;
  
  // Obtain the application process, window and the ComboBoxEx control
  p = Sys.Process("Project1");
  w = p.Window("TForm1", "Form1");
  ComboBoxEx = w.Window("ComboBoxEx32", "");
  
  // Log information about the item's images
  ItemNumber = ComboBoxEx.wItemCount;
  for (let i = 0; i< ItemNumber; i++)
    if (!strictEqual(ComboBoxEx.wItemImage(i), null))
      Log.Picture(ComboBoxEx.wItemImage(i), "Default image");
    else
      Log.Message(ComboBoxEx.wItem(i) + " item does not have an image");
}

JScript

function main()
{
  var p, w, i, ComboBoxEx, ItemNumber;
  
  // Obtain the application process, window and the ComboBoxEx control
  p = Sys.Process("Project1");
  w = p.Window("TForm1", "Form1");
  ComboBoxEx = w.Window("ComboBoxEx32", "");
  
  // Log information about the item's images
  ItemNumber = ComboBoxEx.wItemCount;
  for (i = 0; i< ItemNumber; i++)
    if (ComboBoxEx.wItemImage(i) != null)
      Log.Picture(ComboBoxEx.wItemImage(i), "Default image");
    else
      Log.Message(ComboBoxEx.wItem(i) + " item does not have an image");
}

Python

def Main():

  # Obtain the application process, window and the ComboBoxEx control
  p = Sys.Process("Project1")
  w = p.Window("TForm1", "Form1")
  ComboBoxEx = w.Window("ComboBoxEx32", "")
  
  # Log information about the item's images
  ItemNumber = ComboBoxEx.wItemCount 
  for i in range(0, ItemNumber-1):
    if (ComboBoxEx.wItemImage[i] != None):
      Log.Picture(ComboBoxEx.wItemImage[i], "Default image")
    else:
      Log.Message(ComboBoxEx.wItem[i] + " item does not have an image")

VBScript

Sub Main
  Dim p, w, i, ComboBoxEx, ItemNumber
  
   ' Obtain the application process, window and the ComboBoxEx control
  Set p = Sys.Process("Project1")
  Set w = p.Window("TForm1", "Form1")
  Set ComboBoxEx = w.Window("ComboBoxEx32", "")
  
  ' Log information about the item's images
  ItemNumber = ComboBoxEx.wItemCount
  For i = 0 To ItemNumber-1
     If Not (ComboBoxEx.wItemImage(i) Is Nothing) Then
       Call Log.Picture(ComboBoxEx.wItemImage(i), "Default image")
     Else
       Log.Message(ComboBoxEx.wItem(i) + " item does not have an image")
     End If
  Next 
End Sub

DelphiScript

function main();
var 
  p, w, i, ComboBoxEx, ItemNumber: OleVariant;
begin
  // Obtain the application process, window and the ComboBoxEx control
  p := Sys.Process('Project1');
  w := p.Window('TForm1', 'Form1');
  ComboBoxEx := w.Window('ComboBoxEx32', '');
  
  // Log information about the item's images
  ItemNumber := ComboBoxEx.wItemCount;
  for i := 0 to ItemNumber-1 do
    if (ComboBoxEx.wItemImage(i) <> nil)
    then
      Log.Picture(ComboBoxEx.wItemImage(i), 'Default image')
    else
      Log.Message(ComboBoxEx.wItem(i) + ' item does not have an image');
end;

C++Script, C#Script

function main()
{
  var p, w, i, ComboBoxEx, ItemNumber;
  
  // Obtain the application process, window and the ComboBoxEx control
  p = Sys["Process"]("Project1");
  w = p["Window"]("TForm1", "Form1");
  ComboBoxEx = w["Window"]("ComboBoxEx32", "");
  
  // Log information about the item's images
  ItemNumber = ComboBoxEx["wItemCount"];
  for (i = 0; i< ItemNumber; i++)
    if (ComboBoxEx["wItemImage"](i) != null)
      Log["Picture"](ComboBoxEx["wItemImage"](i), "Default image");
    else
      Log["Message"](ComboBoxEx["wItem"](i) + " item does not have an image");
}

See Also

Working With Combo Box Controls in Desktop Windows Applications
wItemImage Property (Combo Box Controls)
wItemSelectedImage Property (Combo Box Controls)
Picture Object
Working With Combo Box Controls in Web Applications

Highlight search results