Join Wintertainment 2021 to share your stories, have fun, earn community badges, and more!

Addressing Expandable List Groups and Items

Applies to TestComplete 15.10, last modified on December 07, 2021

When using the Android ExplandableList properties and methods to perform specific actions on an expandable list, you should specify the group and/or item you want to work with. This topic explains the principles of addressing list groups and items.

Addressing Groups by Captions

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

expList.Expand("Group 1")          // Expands the first group

expList.TouchItem("Group 2", 0)   // Touch the first item in the second group.

If the expandable list does not display the text of groups, you can find it using the wGroup property. It returns the name of the group specified by its index.

groupName = expList.wGroup(0)    // Returns the name of the first group

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, an expandable list contains a group 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:

expList.TouchItem("Last *", 0)

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

expList.TouchItem("**", 0)

TestComplete can treat string parameters, including expandable list group’ 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:

expList.TouchItem("Item 1", 0)

expList.TouchItem("ITEM 1", 0)

expList.TouchItem("item 1", 0)

expList.TouchItem("ItEm 1", 0)

If the Use case-sensitive parameters is checked, you can specify expandable list groups only by their actual captions in the correct case:

expList.TouchItem("Item 1", 0)  // Correct
expList.TouchItem("iteM 1", 0)  // Incorrect !!!

Addressing Groups by Indexes

If an expandable list 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 groups in an expandable list are specified by the wGroupCount property. So, the last group’s index is wGroupCount-1:

expList.Expand(0)  // Expands the first group

expList.Expand(3)  // Expands the fourth group


expList.Expand(expList.wGroupCount - 1)  // Expands the last group

Addressing Items

Unlike groups, items cannot be specified by their captions. So, you should specify an item by its zero-based index. The total number of items in the group is specified by the wItemCount property. So, the last item’s index in the group is wItemCount-1:

expList.TouchItem("Group 1", 0)  // Touches the first item in the Group 1

expList.TouchItem("Group 1", 3)  // Touches the fourth item in the Group 1

expList.TouchItem("Group 1", expList.wItemCount("Group 1") - 1)  // Touches the last item in the Group 1

Simulating Actions From Keyword Tests

This topic explains how to address items of the expandable list 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 Expandable List Controls

Highlight search results