Selecting a Segment

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

Simulating Touch Actions Over a Segment

To select a segment, use the Touch or TouchButton action of the iOS Segment object that TestComplete associates with that control. This action performs a single short touch on the control. The following example demonstrates how to touch the segment:

JavaScript, JScript

function Test()
{

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

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

  // Touch the segment
  segment.Touch();
  segment.TouchButton();

}

Python

def Test():

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

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

  # Touch the segment
  segment.Touch()
  segment.TouchButton()

VBScript

Sub Test

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

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

  ' Touch the segment
  segment.Touch
  segment.TouchButton

End Sub

DelphiScript

procedure Test();
var p, segment;
begin

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

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

  // Touch the segment
  segment.Touch();
  segment.TouchButton();

end;

C++Script, C#Script

function Test()
{

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

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

  // Touch the segment
  segment["Touch"]();
  segment["TouchButton"]();

}

Simulating Touch Actions Over a Segmented Control's Item

Alternatively, you can select a specific segment of a segmented control by calling the TouchItem or LongTouchItem action of the corresponding iOS SegmentedControl object. These actions perform a touch over the item specified by its zero-based index or caption. The following example touches the first segment of a segmented control:

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

  // Touch a segment
  segmentedControl.TouchItem(0);

}

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

  # Touch a segment 
  segmentedControl.TouchItem(0)

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

  ' Touch a segment
  segmentedControl.TouchItem(0)

End Sub

DelphiScript

procedure Test();
var p, segmentedControl;
begin

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

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

  // Touch a segment
  segmentedControl.TouchItem(0);

end;

C++Script, C#Script

function Test()
{

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

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

  // Touch a segment
  segmentedControl["TouchItem"](0);

}

Simulating Actions in Keyword Tests

To select a segment 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 Segments and Segmented Controls
Determining a Segment's State
Touch Action (Mobile Objects)
TouchButton Action (Mobile Controls)

Highlight search results