Getting the Number of Segments in a Segmented Control

Applies to TestComplete 15.47, last modified on January 20, 2023

Getting the wItemCount Property

To get the number of segments contained in a segmented control, use the wItemCount property of the iOS SegmentedControl object that TestComplete associates with that control.

The following example demonstrates how to obtain and post the number of segments in a segmented control to the test log:

JavaScript, JScript

function Test()
{
  // Select the iOS device
  Mobile.SetCurrent("iPhone");

  // Obtain the SegmentedControl object
  var p = Mobile.Device().Process("SampleApp");
  var segmentedControl = p.Window(0).TableView().SegmentedControl();

  // Get the number of segmentes
  var count = segmentedControl.wItemCount;

  // Post the number to the log
  Log.Message(count);

}

Python

def Test():
  # Select the iOS device
  Mobile.SetCurrent("iPhone")

  # Obtain the SegmentedControl object
  p = Mobile.Device().Process("SampleApp")
  segmentedControl = p.Window(0).TableView().SegmentedControl()

  # Get the number of segmentes
  count = segmentedControl.wItemCount

  # Post the number to the log
  Log.Message(count)

VBScript

Sub Test

  ' Select the iOS device
  Mobile.SetCurrent("iPhone")

  ' Obtain the SegmentedControl object
  Set p = Mobile.Device.Process("SampleApp")
  Set segmentedControl = p.Window(0).TableView().SegmentedControl

  ' Get the number of segmentes
  count = segmentedControl.wItemCount

  ' Post the number to the log
  Log.Message count

End Sub

DelphiScript

procedure Test();
var p, segmentedControl, count;
begin
  // Select the iOS device
  Mobile.SetCurrent('iPhone');

  // Obtain the SegmentedControl object
  p := Mobile.Device.Process('SampleApp');
  segmentedControl := p.Window(0).TableView().SegmentedControl;

  // Get the number of segmentes
  count := segmentedControl.wItemCount;

  // Post the number to the log
  Log.Message(count);

end;

C++Script, C#Script

function Test()
{
  // Select the iOS device
  Mobile["SetCurrent"]("iPhone");

  // Obtain the SegmentedControl object
  var p = Mobile["Device"]["Process"]("SampleApp");
  var segmentedControl = p["Window"](0)["TableView"]()["SegmentedControl"]();

  // Get the number of segmentes
  var count = segmentedControl["wItemCount"];

  // Post the number to the log
  Log["Message"](count);

}

Getting the Number of Segments in Keyword Tests

To get the number of segments contained in a segmented 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 Segments and Segmented Controls
Selecting a Segment
Determining a Segment's State

Highlight search results