Scrolling Table View

Applies to TestComplete 14.71, last modified on April 22, 2021

The TableView control can contain items not visible on the screen. This topic describes how to scroll the table view:

Setting Table View Position

When working with iOS TableView, you may need to check the state of an item that is not immediately visible. This may be a problem since iOS does not create objects that are not visible on the screen. You can still perform actions on the item - for example, a Touch action scrolls the view to the item you simulate the touch on, but getting the object's properties is impossible without having it on the screen. You can perform the Touch action to scroll to it, but, in most cases, it is undesirable, since it may influence the item.

TestComplete provides a special ScrollToItem method that you can use to scroll to the specified item in the specified section. This method scroll to the position in the table view and returns the object, with which you can then work as described in the Working With Objects in Table View Items topic. The following example scrolls to the first item in the second section of the table view:

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();
  
  // Scroll to the first item of the second section
  tableview.ScrollToItem(1, 0);
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the TableView object 
  p = Mobile.Device().Process("SampleApp")
  tableview = p.Window().TableView()
  
  # Scroll to the first item of the second section
  tableview.ScrollToItem(1, 0)

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()
  
  ' Scroll to the first item of the second section
  Call tableview.ScrollToItem(1, 0)
End Sub

DelphiScript

procedure Test();
var
  p, tableview;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the tableview object
  p := Mobile.Device.Process('SampleApp');
  tableview := p.Window(0).TableView(0);
  
  // Scroll to the first item of the second section
  tableview.ScrollToItem(1, 0);
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"]();
  
  // Scroll to the first item of the second section
  tableview["ScrollToItem"](1, 0);
}

Another way to scroll the table view is to use the wPositionY and wPositionX properties of the iOS TableView object. These properties allow you to set the position of the visible area. The value you use defines the distance to the topmost and leftmost areas of the control respectively. They should be within wMinY and wMaxY for wPositionY and wMinX and wMaxX for wPositionX.

Here is the example of how to scroll half screen downwards:

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

  // Change TableView position
  tableview.wPositionY = tableview.Height/2;
}

Python

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

  # Change TableView position
  tableview.wPositionY = tableview.Height/2

VBScript

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

  ' Change TableView position
  tableview.wPositionY = tableview.Height/2
End Sub

DelphiScript

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

  // Change TableView position
  tableview.wPositionY := tableview.Height/2;
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"]();

  // Change TableView position
  tableview["wPositionY"] = tableview["Height"]/2;
}

Simulating Actions From Keyword Tests

To scroll 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
wPositionX Property (iOS Controls)
wPositionY Property (iOS Controls)

Highlight search results