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:
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 !!!
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
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.