Getting a Segment's Text

Applies to TestComplete 15.42, last modified on September 08, 2022

When testing an application that uses segmented controls, you may need to obtain a segment’s caption. This topic describes how to do this.

Using wItem Property

To obtain a caption of an individual segment that belongs to a segmented control in your iOS application, use the wItem property of the appropriate iOS SegmentedControl object. The property returns the caption of the segment specified by its index.

The following code sample demonstrates how to get the segment’s caption:

JavaScript, JScript

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

  // Post the items text to the log
  Log.Message(segmentedControl.wItem(1));
}

Python

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

  # Post the items text to the log
  Log.Message(segmentedControl.wItem[1])

VBScript

Sub Test()
  Dim p, segmentedControl
  
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the PickerView object
  Set p = Mobile.Device.Process("SampleApp")
  Set segmentedControl = p.Window.SegmentedControl

  ' Post the items text to the log
  Log.Message(segmentedControl.wItem(1))
End Sub

DelphiScript

function Test();
var p, segmentedControl;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the PickerView object
  p := Mobile.Device.Process('SampleApp');
  segmentedControl := p.Window.SegmentedControl;

  // Post the items text to the log
  Log.Message(segmentedControl.wItem(1));
end;

C++Script, C#Script

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

  // Post the items text to the log
  Log["Message"](segmentedControl["wItem"](1));
}

Getting the Text of Segments in Keyword Tests

To get the text 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
iOS Segment Support
wItem Property (Mobile Controls)
wItemCount Property (Mobile Controls)

Highlight search results