Working with ScrollView in Paging Mode

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

Scroll view controls support paging. When the paging mode of the control is enabled, it allows scrolling a single screen of content at a time.

Working with scroll view controls in paging mode is similar to working with iOS page controls.

Determining Number of Pages

To determine the number of pages in the scroll view, you can use the wPageCount property of the iOS ScrollView test object that TestComplete automatically associates with the scroll view control.

The following sample code obtains the number of pages in the scroll view and posts it to the test log:

JavaScript, JScript

function Test()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Obtain the ScrollView object
  var p = Mobile.Device().Process("SampleApp");
  var scrollview = p.Window().ScrollView();
  
  Log.Message(scrollview.wPageCount);
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the ScrollView object 
  p = Mobile.Device().Process("SampleApp")
  scrollview = p.Window().ScrollView()
  
  Log.Message(scrollview.wPageCount)

VBScript

Sub Test()
  Dim p, scrollview
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the ScrollView object
  Set p = Mobile.Device.Process("SampleApp")
  Set scrollview = p.Window.ScrollView
  
  Log.Message(scrollview.wPageCount)
End Sub

DelphiScript

procedure Test();
var
  p, scrollview;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the ScrollView object
  p := Mobile.Device.Process('SampleApp');
  scrollview := p.Window.ScrollView;
  
  Log.Message(scrollview.wPageCount);
end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");
  // Obtain the ScrollView object
  var p = Mobile["Device"].Process("SampleApp");
  var scrollview = p["Window"]()["ScrollView"]();
  
  Log["Message"](scrollview["wPageCount"]);
}

Determining Currently Selected Page

To determine which page is currently selected in the scroll view, you can use the wPage property of the iOS ScrollView test object TestComplete automatically associates with the scroll view control.

The sample code checks whether the second page is selected. If it is not, the code selects the needed page:

JavaScript, JScript

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

  // Check whether the needed page is selected
  if (scrollview.wPage == 1)
    Log.Message("The second page is selected");
  else
    scrollview.ScrollToPage(1);
}

Python

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

  # Check whether the needed page is selected
  if (scrollview.wPage == 1):
    Log.Message("The second page is selected")
  else:
    scrollview.ScrollToPage(1)

VBScript

Sub Test
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the PageControl object
  Set p = Mobile.Device.Process("SampleApp")
  Set pageControl = p.Window().ScrollView

  ' Check whether the needed page is selected
  If scrollview.wPage = 1 Then
    Log.Message("The second page is selected")
  Else
    scrollview.ScrollToPage(1)
  End If
End Sub

DelphiScript

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

  // Check whether the needed page is selected
  if scrollview.wPage = 1 then
    Log.Message('The second page is selected')
  else
    scrollview.ScrollToPage(1);
end;

C++Script, C#Script

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

  // Check whether the needed page is selected
  if (scrollview["wPage"] == 1)
    Log["Message"]("The second page is selected");
  else
    scrollview["ScrollToPage"](1);
}

Navigating Through Pages

To select the page preceding or following the page that is currently selected in the scroll view, use the Back and Next methods of the iOS ScrollView test object. To select an arbitrary page (specified by its index), you can call the ScrollToPage method of the iOS ScrollView object, or assign page index to the wPage property.

The code sample below demonstrates how to use the methods to navigate through pages:

JavaScript, JScript

function Test()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Obtain the ScrollView object
  var p = Mobile.Device().Process("SampleApp");
  var scrollview = p.Window().ScrollView();
  
  scrollview.ScrollToPage(1)
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the ScrollView object 
  p = Mobile.Device().Process("SampleApp")
  scrollview = p.Window().ScrollView() 
  
  scrollview.ScrollToPage(1)

VBScript

Sub Test()
  Dim p, scrollview
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the ScrollView object
  Set p = Mobile.Device.Process("SampleApp")
  Set scrollview = p.Window.ScrollView
  
  scrollview.ScrollToPage(1)
End Sub

DelphiScript

procedure Test();
var
  p, scrollview;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the ScrollView object
  p := Mobile.Device.Process('SampleApp');
  scrollview := p.Window.ScrollView;
  
  scrollview.ScrollToPage(1)
end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Obtain the ScrollView object
  var p = Mobile.Device.Process("SampleApp");
  var scrollview = p.Window().ScrollView();
  
  scrollview.ScrollToPage(1)
}

Working with ScrollView in Paging Mode From Keyword Tests

To work with scroll view in paging mode 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 Scroll View Controls
Changing ScrollView Position
wPage Property (iOS Controls)
ScrollToPage Method (iOS Controls)
wPageCount Property (iOS Controls)
Next Method (iOS Controls)
Back Method (iOS Controls)

Highlight search results