When you test an Android application that uses list view controls, you may need to obtain captions of items of the list view controls. This topic describes how to do this.
Using the wItem Property
The Android ListView
object that corresponds to the tested list view control provides a set of properties that allow you to get the text of the list view control’s individual items. To obtain the text of an item, use the wItem
property.
The following code snippet demonstrates how to get a list view item’s caption:
JavaScript, JScript
function Test()
{
// Select an Android device
Mobile.SetCurrent("MyDevice");
// Obtain a list view
var app = Mobile.Device().Process("com.example.myapp");
var listviewObj = app.RootLayout("").Layout("layout1").ListView("listview1");
// Obtain the text of the first item and post it to the test log
var text = listviewObj.wItem(0);
Log.Message(text);
}
Python
def Test():
# Select an Android device
Mobile.SetCurrent("MyDevice")
# Obtain a list view
app = Mobile.Device().Process("com.example.myapp")
listviewObj = app.RootLayout("").Layout("layout1").ListView("listview1")
# Obtain the text of the first item and post it to the test log
text = listviewObj.wItem[0]
Log.Message(text)
VBScript
Sub Test()
Dim app, listviewObj, text
' Select an Android device
Mobile.SetCurrent("MyDevice")
' Obtain a list view
Set app = Mobile.Device.Process("com.example.myapp")
Set listviewObj = app.RootLayout("").Layout("layout1").ListView("listview1")
' Obtain the text of the first item and post it to the test log
text = listviewObj.wItem(0)
Log.Message(text)
End Sub
DelphiScript
procedure Test();
var
app, listviewObj, text: OleVariant;
begin
// Select an Android device
Mobile.SetCurrent('MyDevice');
// Obtain a list view
app := Mobile.Device.Process('com.example.myapp');
listviewObj := app.RootLayout('').Layout('layout1').ListView('listview1');
// Obtain the text of the first item and post it to the test log
text := listviewObj.wItem(0);
Log.Message(text);
end;
C++Script, C#Script
function Test()
{
// Select an Android device
Mobile["SetCurrent"]("MyDevice");
// Obtain a list view
var app = Mobile["Device"]["Process"]("com.example.myapp");
var listviewObj = app["RootLayout"]("")["Layout"]("layout1")["ListView"]("listview1");
// Obtain the text of the first item and post it to the test log
var text = listviewObj["wItem"](0);
Log["Message"](text);
}
Note: | To get the total number of items the list view control contains, use the wItemCount property. |
Simulating Actions From Keyword Tests
This topic explains how to get item’s text of the list view control in scripts. You can use the described 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
Android ListView Support
wItem Property (Mobile Controls)
wItemCount Property (Mobile Controls)