Addressing List View Items

Applies to TestComplete 15.47, last modified on January 20, 2023

When using the Android ListView properties and methods to perform specific actions on a list view, you should specify the item you want to work with. This topic explains the principles of addressing list view items.

Addressing Items by Captions

In the Android ListView properties and methods, you can specify the desired list view item by its caption or index. Usually, it is more convenient to address groups and items by caption, because it makes the script easier to understand:

listViewObj.TouchItem("Item 1")          // Selects the first item

It is possible to use wildcard characters (* and ?) or regular expressions when specifying the caption. The asterisk (*) corresponds to a string of any length (including an empty string), the question mark corresponds to any single character (including none). Wildcards and regular expressions are useful if the list group’ captions can be different in different contexts.

For example, the list contains an item whose caption depends on the current day of the week, for instance, Last Wednesday or Last Monday. To create a script that will work on different days, you can use the * wildcard instead of some part of the caption:

listViewObj.TouchItem("Last *")

Note, if the item’s caption includes the asterisk (*), you should double it, otherwise it will be treated as a wildcard:

listViewObj.TouchItem("**")

TestComplete can treat string parameters, including list view items’ captions, as case-sensitive or case-insensitive. This feature is controlled by the project’s Use case-sensitive parameters option. If this option is turned off (it is off by default), you can specify the captions of list view items and subitems in any case -- all upper case, all lower case, mixed case, and so on:

listViewObj.TouchItem("Item 1")

listViewObj.TouchItem("ITEM 1")

listViewObj.TouchItem("item 1")

listViewObj.TouchItem("ItEm 1")

If the Use case-sensitive parameters is checked, you can specify list view items and subitems only by their actual captions in the correct case:

listViewObj.TouchItem("Item 1")  // Correct
listViewObj.TouchItem("iteM 1")  // Incorrect !!!

Addressing Items by Indexes

If a list view item or group does not have a caption, you can address it by its index. Indexes are zero-based: the first item has the index 0, the second - 1, and so on. The total number of items in a list view are specified by the wItemCount property. So, the last item’s index is wItemCount-1:

listViewObjTouchItem(0)  // Clicks the first item

listViewObj.TouchItem(3)  // Clicks the fourth item


listViewObj.SelectItem(listViewObj.wItemCount - 1)  // Selects the last item

Simulating Actions From Keyword Tests

This topic explains how to address items of the list view control in scripts. You can use the described actions and properties in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.

See Also

Working With Android List View Controls

Highlight search results