Working With Third-Party List View Controls in Desktop Windows Applications

Applies to TestComplete 15.45, last modified on December 01, 2022

TestComplete supports various types of controls included in various Win32, .NET, WPF, Java and other frameworks and provides special objects to work with each supported control. For example, to work with standard Win32 list views, it uses methods and properties of the Win32ListView object.

Besides Win32 list views, TestComplete provides extended support for WPF (XAML) ListView controls via the WPFListView object. The core functionality of this object is similar to the Win32ListView functionality, since it has a number of ClickItem actions that simulate mouse clicks on list view items, the wItem property that returns the item’s text, the wItemCount property that holds the number of items, and so on. For the complete members list, see the WPFListView object description. Most information provided in Working With List View Controls in Desktop Windows Applications can be applied to WPF (XAML) ListView controls as well.

While testing list view 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 following example works with the XAMLPad application, which is a part of the Windows SDK. Before running the script, you should launch XAMLPad and replace the editor contents with the following code:

XAML

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ListView>
    <ListView.Items>
        <ListViewItem>Item 1</ListViewItem>
        <ListViewItem>Item 2</ListViewItem>
        <ListViewItem>Item 3</ListViewItem>
        <ListViewItem>Item 4</ListViewItem>
        <ListViewItem>Item 5</ListViewItem>
        <ListViewItem>Item 6</ListViewItem>
        <ListViewItem>Item 7</ListViewItem>
        <ListViewItem>Item 8</ListViewItem>
        <ListViewItem>Item 9</ListViewItem>
        <ListViewItem>Item 10</ListViewItem>
    </ListView.Items>
</ListView>
</Page>

This script interacts with the list view control by using the WPFListView object’s actions and properties. In addition, it uses the list view’s “native”SelectedItems.Count property to obtain the number of selected items.

JavaScript, JScript

function Main()
{
  var p, w, ListView, Items;

  // Obtain the XAMLPad process, window and the ListView control
  p = Sys.Process("XAMLPad");
  w = p.WPFObject("HwndSource: Window", "XamlPad");
  ListView = w.FindChild("ClrClassName", "ListView", 10);

  // Select a range of items
  ListView.ClickItem("Item 1");
  ListView.ClickItem("Item 4", skShift);
  // Add two more items to the selection
  ListView.ClickItem("Item 6", skCtrl);
  ListView.ClickItem("Item 9", skCtrl);

  // Log information about the selected items
  ListView.wListSeparator = ", ";
  Log.Message("Items selected in the ListView:\r\n" + ListView.wSelectedItems);
  Log.Message("The number of selected items: " + ListView.SelectedItems.Count);
}

Python

def Main():

  # Obtain the XAMLPad process, window and the ListView control
  p = Sys.Process("XAMLPad")
  w = p.WPFObject("HwndSource: Window", "XamlPad")
  ListView = w.FindChild("ClrClassName", "ListView", 10)

  # Select a range of items
  ListView.ClickItem("Item 1")
  ListView.ClickItem("Item 4", skShift)
  
  # Add two more items to the selection
  ListView.ClickItem("Item 6", skCtrl)
  ListView.ClickItem("Item 9", skCtrl)

  # Log information about the selected items
  ListView.wListSeparator = ", "
  Log.Message("Items selected in the ListView:\r\n" + ListView.wSelectedItems)
  Log.Message("The number of selected items: " + ListView.SelectedItems.Count)

VBScript

Sub Main
  Dim p, w, ListView, Items

  ' Obtain the XAMLPad process, window and the ListView control
  Set p = Sys.Process("XAMLPad")
  Set w = p.WPFObject("HwndSource: Window", "XamlPad")
  Set ListView = w.FindChild("ClrClassName", "ListView", 10)

  ' Select a range of items
  ListView.ClickItem("Item 1")
  Call ListView.ClickItem("Item 4", skShift)
  ' Add two more items to the selection
  Call ListView.ClickItem("Item 6", skCtrl)
  Call ListView.ClickItem("Item 9", skCtrl)

  ' Log information about the selected items
  ListView.wListSeparator = ", "
  Log.Message("Items selected in the ListView:" & vbNewLine & ListView.wSelectedItems)
  Log.Message("The number of selected items: " & ListView.SelectedItems.Count)
End Sub

DelphiScript

procedure Main;
var p, w, ListView, Items : OleVariant;
begin
  // Obtain the XAMLPad process, window and the ListView control
  p := Sys.Process('XAMLPad');
  w := p.WPFObject('HwndSource: Window', 'XamlPad');
  ListView := w.FindChild('ClrClassName', 'ListView', 10);

  // Select a range of items
  ListView.ClickItem('Item 1');
  ListView.ClickItem('Item 4', skShift);
  // Add two more items to the selection
  ListView.ClickItem('Item 6', skCtrl);
  ListView.ClickItem('Item 9', skCtrl);

  // Log information about the selected items
  ListView.wListSeparator := ', ';
  Log.Message('Items selected in the ListView:' + #13#10 + ListView.wSelectedItems);
  Log.Message('The number of selected items: ' + aqConvert.VarToStr(ListView.SelectedItems.Count));
end;

C++Script, C#Script

function Main()
{
  var p, w, ListView, Items;

  // Obtain the XAMLPad process, window and the ListView control
  p = Sys["Process"]("XAMLPad");
  w = p["WPFObject"]("HwndSource: Window", "XamlPad");
  ListView = w["FindChild"]("ClrClassName", "ListView", 10);

  // Select a range of items
  ListView["ClickItem"]("Item 1");
  ListView["ClickItem"]("Item 4", skShift);
  // Add two more items to the selection
  ListView["ClickItem"]("Item 6", skCtrl);
  ListView["ClickItem"]("Item 9", skCtrl);

  // Log information about the selected items
  ListView["wListSeparator"] = ", ";
  Log["Message"]("Items selected in the ListView:\r\n" + ListView["wSelectedItems"]);
  Log["Message"]("The number of selected items: " + ListView["SelectedItems"]["Count"]);
}

However, if your tested application uses custom list view components, TestComplete may not be able to recognize them. In this case, you will be able to work with custom list views in the black-box mode only, that is, simulate mouse clicks and keystrokes, record and play back low-level procedures, and so on. However, TestComplete includes several features that can provide deeper access to the control’s internals:

  • You can map your custom list view control to one of supported list view types using Object Mapping. In this case, TestComplete will try to handle the mapped control as a standard control and work with it via the corresponding scripting object (for example, Win32ListView).

  • If your application is Open, you can use the list view’s internal properties and methods to select individual items, obtain their data and perform other actions. To learn which properties and methods can be used to accomplish the desired task, explore the list view control in the Object Browser, see the documentation on the control or consult the tested application’s developers.

  • If the tested application is developed using Microsoft UI Automation Framework, you can expose information about the tested application’s UI elements. See Using Microsoft UI Automation Technology.

  • If your custom list view control implements the IAccessible interface, you can work with it using the TestComplete MSAA engine. See Using Microsoft Active Accessibility.

  • To retrieve the list view item’s data, you can “read” the text in it using optical character recognition. You can locate an item or subitem by its text to select the item in the list view.

For more information about retrieving data stored in custom controls, see Interacting With Non-Compatible Application Objects.

See Also

Working With List View Controls in Desktop Windows Applications
Object-Specific Tasks
Object Mapping
Interacting With Non-Compatible Application Objects

Highlight search results