Getting Section, Item, Detail Text in TableView

Applies to TestComplete 15.20, last modified on January 19, 2022

The items in your application may have different text depending on the actions performed. You may need to test if the test is correct, or use the text of the item to address it later.

Simulating Touches on Items

The iOS TableView object, which is used to work with table views, provides a number of properties that allow you to get text within the table view:

  • wSection property returns the text of the section. You need to specify a section index.

  • wItem property returns the text of an item. You need to specify a section by its name or index, and an item by its index.

  • wItemDetail property returns the text from the details section of an item. You need to specify a section and an item by their name or index.

Note: For more information about the table view layout, see Working With Table View Controls - Basic Concepts

The following example iterates through all sections and items of the table view and posts their text to the log:

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();

  // Post item text to the log
  for (var i = 0; i<tableview.wSectionCount; i++)
  {
    Log.Message(tableview.wSection(i));
    for (var n = 0; n<tableview.wItemCount(i); n++)
    {
      Log.Message(tableview.wItem(i, n));
      Log.Message(tableview.wItemDetail(i, n));
      Log.Message(tableview.wItemSelected(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()

  # Post item text to the log
  for i in range(0, tableview.wSectionCount-1):
    Log.Message(tableview.wSection[i])
    for n in range(0, tableview.wItemCount[i]-1):
      Log.Message(tableview.wItem[i, n])
      Log.Message(tableview.wItemDetail[i, n])
      Log.Message(tableview.wItemSelected[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()

  ' Post item text to the log
  For i = 0 To tableview.wSectionCount-1
    Log.Message(tableview.wSection(i))
    for n = 0 To tableview.wItemCount(i)-1
      Log.Message(tableview.wItem(i, n))
      Log.Message(tableview.wItemDetail(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);

  // Post item text to the log
  for i := 0 to tableview.wSectionCount-1 do
  begin
    Log.Message(tableview.wSection(i));
    for n := 0 to tableview.wItemCount(i)-1 do
      begin
      Log.Message(tableview.wItem(i, n));
      Log.Message(tableview.wItemDetail(i, n));
      Log.Message(tableview.wItemSelected(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"]();

  // Post item text to the log
  for (var i = 0; i<tableview["wSectionCount"]; i++)
  {
    Log["Message"](tableview["wSection"](i));
    for (var n = 0; n<tableview["wItemCount"](i); n++)
    {
      Log["Message"](tableview["wItem"](i, n));
      Log["Message"](tableview["wItemDetail"](i, n));
      Log["Message"](tableview["wItemSelected"](i, n));
    }
  }
}

Simulating Actions From Keyword Tests

To get the text of the 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
wItemDetail Property (iOS TableView Controls)
wItem Property (iOS TableView Controls)
wSection Property (Specific to iOS TableView Controls)

Highlight search results