Determining a Switch's State

Applies to TestComplete 15.47, last modified on January 20, 2023
Getting the value of the wState Property

To determine the state of a switch, use the wState property of the iOS Switch object that TestComplete associates with that control. If the switch is in the "on" state, this property returns 1 or True; otherwise - 0 or False. The following example determines the state of a switch and posts information on the state to the log:

JavaScript, JScript

function Test()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Obtain the switch object
  var p = Mobile.Device().Process("SampleApp");
  var Switch = p.Window(0).Switch(1);
  
  // Post the switch state to the log
  Log.Message(Switch.wState);
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the switch object
  p = Mobile.Device().Process("SampleApp")
  Switch = p.Window(0).Switch(1)
  
  # Post the switch state to the log
  Log.Message(Switch.wState)

VBScript

Sub Test()
  Dim p, Switch
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the switch object
  Set p = Mobile.Device.Process("SampleApp")
  Set Switch = p.Window(0).Switch(0)
  
  ' Post the switch state to the log
  Log.Message(Switch.wState)
End Sub

DelphiScript

procedure Test();
var
  p, Switch;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the switch object
  p := Mobile.Device.Process('SampleApp');
  Switch := p.Window(0).Switch(0);
  
  // Post the switch state to the log
  Log.Message(Switch.wState);
end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");
  // Obtain the switch object
  var p = Mobile["Device"].Process("SampleApp");
  var Switch = p["Window"](0)["Switch"](1);
  
  // Post the switch state to the log
  Log["Message"](Switch["wState"]);
}

Getting the Sate of a Switch in Keyword Tests

To determine the switch state 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 Switch Controls
wState Property (Mobile Controls)

Highlight search results