Determining a Segment's State

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

Getting wChecked Property

To determine the state of a segment, use the wChecked property of the iOS Segment object that TestComplete associates with that control. If the segment is selected, the wChecked property returns True; otherwise, False. The following example demonstrates how to obtain information about the state of 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);

  // Check whether the segment is checked
  if (segment.wChecked)
    Log.Message("This segment is selected");
  else
    Log.Message("This segment is not selected");

}

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)

  # Check whether the segment is checked
  if segment.wChecked:
    Log.Message("This segment is selected")
  else:
    Log.Message("This segment is not selected")

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)

  ' Check whether the segment is checked
  If segment.wChecked Then
    Log.Message "This segment is selected"
  else
    Log.Message "This segment is not selected"
  End If

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

  // Check whether the segment is checked
  if segment.wChecked then
    Log.Message('This segment is selected')
  else
    Log.Message('This segment is not selected');

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

  // Check whether the segment is checked
  if (segment["wChecked"])
    Log["Message"]("This segment is selected");
  else
    Log["Message"]("This segment is not selected");

}

Checking State in Keyword Tests

To check a segment’s state in keyword tests, use the On-Screen Action or Call Object Method operation to obtain the value of the wChecked property.

See Also

Working With iOS Segments and Segmented Controls
wChecked Property (Mobile Controls)

Highlight search results