Iterating Through Table View Items

Applies to TestComplete 14.30, last modified on November 21, 2019

When testing applications, you may need to get the value of all items in a table view, or perform an action on them.

Iterating Through Items and Sections

To iterate through items of a table view, you need to know the number of sections and the number of items in each section. To get these, use the wSectionCount and wItemCount properties. The following example iterates through all items of the table view and touches them.

JavaScript, JScript

function Test()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Obtain the TableView object
  var p = Mobile.Device().Process("SampleApp");
  var tableview = p.Window().TableView();

  // Iterate through items
  for (var i = 0; i<tableview.wSectionCount; i++)
  {
    for (var n = 0; n<tableview.wItemCount(i); n++)
    {
      tableview.TouchItem(i, n)
    }
  }
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the TableView object 
  p = Mobile.Device().Process("SampleApp")
  tableview = p.Window().TableView()

  # Iterate through items
  for i in range(0, tableview.wSectionCount-1):
    for n in range(0, tableview.wItemCount[i]-1):
      tableview.TouchItem(i, n)

VBScript

Sub Test()
  Dim p, tableview
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the TableView object
  Set p = Mobile.Device.Process("SampleApp")
  Set tableview = p.Window().TableView()

  ' Iterate through items
  For i = 0 To tableview.wSectionCount-1
    Log.Message(tableview.wSection(i))
    for n = 0 To n<tableview.wItemCount(i)-1
       Call tableview.TouchItem(i, n)
    Next
  Next
End Sub

DelphiScript

procedure Test();
var
  p, tableview, i, n;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the TableView object
  p := Mobile.Device.Process('SampleApp');
  tableview := p.Window(0).TableView(0);

  // Iterate through items
  for i := 0 to tableview.wSectionCount-1 do
  begin
    for n := 0 to tableview.wItemCount(i)-1 do
      begin
         tableview.TouchItem(i, n);
      end;
  end;
end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");
  // Obtain the TableView object
  var p = Mobile["Device"].Process("SampleApp");
  var tableview = p["Window"]()["TableView"]();

  // Iterate through items
  for (var i = 0; i<tableview["wSectionCount"]; i++)
  {
    Log["Message"](tableview["wSection"](i));
    for (var n = 0; n<tableview["wItemCount"](i); n++)
    {
       tableview["TouchItem"](i, n);
    }
  }
}

Simulating Actions From Keyword Tests

To iterate through items of table views from keyword tests, call the methods described above by using the On-Screen Action or Call Object Method operation. See Calling Object Methods.

See Also

Working With iOS Table View Controls
wItemCount Property (Specific to iOS TableView Controls)
wSectionCount Property (Specific to iOS TableView Controls)

Highlight search results