Determining the Selected Page

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

When testing iOS applications that contain several pages, you may need to determine which page is currently selected in the page control. This topic describes how to check which page is selected from tests.

Using the wSelectedPage Property

To determine which page is currently selected in the page control, you can use the wSelectedPage property of the iOS PageControl test object TestComplete automatically associates with the page 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 pageControl = p.Window().PageControl();

  // Check whether the needed page is selected
  if (pageControl.wSelectedPage == 1)
    Log.Message("The second page is selected");
  else
    pageControl.SelectPage(1);
}

Python

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

  # Check whether the needed page is selected
  if (pageControl.wSelectedPage == 1):
    Log.Message("The second page is selected")
  else:
    pageControl.SelectPage(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().PageControl

  ' Check whether the needed page is selected
  If pageControl.wSelectedPage = 1 Then
    Log.Message("The second page is selected")
  Else
    pageControl.SelectPage(1)
  End If
End Sub

DelphiScript

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

  // Check whether the needed page is selected
  if pageControl.wSelectedPage = 1 then
    Log.Message('The second page is selected')
  else
    pageControl.SelectPage(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 pageControl = p["Window"]()["PageControl"]();

  // Check whether the needed page is selected
  if (pageControl["wSelectedPage"] == 1)
    Log["Message"]("The second page is selected");
  else
    pageControl["SelectPage"](1);
}

Determining the Selected Page From Keyword Tests

To determine what page is currently selected in the page control from keyword tests, use the On-Screen Action or Call Object Method operation to access the properties described above. See Getting and Setting Object Property Values.

See Also

Working With iOS Page Controls
Navigating Through Application Pages
wSelectedPage Property (Specific to iOS PageControl)

Highlight search results