Determining the Currently Selected Segment

Applies to TestComplete 15.69, last modified on November 13, 2024

Getting wSelectedItem Property

To check which segment is currently selected, use the wSelectedItem property of the iOS SegmentedControl object. This property returns the zero-based index of the selected item. The following example demonstrates how to use the property to obtain the index of the selected segment:

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

  // Obtain the index of the selected segment
  var ind = segmentedControl.wSelectedItem;
  Log.Message("The segmented with the index " + aqConvert.VarToStr(ind) + " is selected.");

}

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

  # Obtain the index of the selected segment
  ind = segmentedControl.wSelectedItem
  Log.Message("The segmented with the index " + str(ind) + " is selected.")

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

  ' Obtain the index of the selected segment
  ind = segmentedControl.wSelectedItem
  Log.Message("The segmented with the index " + aqConvert.VarToStr(ind) + " is selected.")

End Sub

DelphiScript

procedure Test();
var p, segmentedControl, ind;
begin

  // Select the iOS device
  Mobile.SetCurrent('iPhone');

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

  // Obtain the index of the selected segment
  ind := segmentedControl.wSelectedItem;
  Log.Message('The segmented with the index ' + aqConvert.VarToStr(ind) + ' is selected.');

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

  // Obtain the index of the selected segment
  var ind = segmentedControl["wSelectedItem"];
  Log["Message"]("The segmented with the index " + aqConvert["VarToStr"](ind) + " is selected.");

}

Getting the Selected Segment in Keyword Tests

To determine the currently selected segment 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
wSelectedItem Property (Mobile Controls)

Highlight search results