Working With Objects in Table View Items

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

Table views can contain objects such as sliders, steppers, buttons, and so on. It is possible to find them through the Object Tree, but is generally not recommended since the item may be off-screen and thus unavailable, and the index of the TableViewCell child item may differ depending on the screen position. TestComplete provides a simpler way to work with such controls.

Working with Objects in Table View

The iOS TableView object, which is used to work with table views, provides a ScrollToItem method that places the specified item on the screen and returns the reference to the item's object. Note that the returned object refers to the item and not the control placed in it. The following example obtains the item object of the tableview, and then posts the position of slider within in 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();
  
  // Get the reference to the item
  var ItemObj = tableview.ScrollToItem(1, 0);
  
  // Post the position of the slider to the log
  Log.Message(ItemObj.ScrollView().Slider().wPosition);
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the TableView object 
  p = Mobile.Device().Process("SampleApp")
  tableview = p.Window().TableView()
  
  # Get the reference to the item
  ItemObj = tableview.ScrollToItem(1, 0)
  
  # Post the position of the slider to the log
  Log.Message(ItemObj.ScrollView().Slider().wPosition)

VBScript

Sub Test()
  Dim p, tableview, ItemObj
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the TableView object
  Set p = Mobile.Device.Process("SampleApp")
  Set tableview = p.Window().TableView()
  
  ' Get the reference to the item
  ItemObj = tableview.ScrollToItem(1, 0)
  
  ' Post the position of the slider to the log
  Log.Message(ItemObj.ScrollView().Slider().wPosition)
End Sub

DelphiScript

procedure Test();
var
  p, tableview, ItemObj;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the tableview object
  p := Mobile.Device.Process('SampleApp');
  tableview := p.Window(0).TableView(0);
  
  // Get the reference to the item
  ItemObj := tableview.ScrollToItem(1, 0);
  
  // Post the position of the slider to the log
  Log.Message(ItemObj.ScrollView().Slider().wPosition);
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"]();
  
  // Get the reference to the item
  var ItemObj = tableview["ScrollToItem"](1, 0);
  
  // Post the position of the slider to the log
  Log["Message"](ItemObj["ScrollView"]()["Slider"]()["wPosition"]);
}

Note: Objects within table view can also be accessed via Object spy, but since the TableViewCell index may vary depending on the screen position, you should only use it to check properties and methods of the control you plan to work with.

Simulating Actions From Keyword Tests

To work with items within 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
ScrollToItem Method (Specific to iOS TableView Controls)

Highlight search results