Determining a Toggle Button's State

Applies to TestComplete 15.47, last modified on January 20, 2023
Simulating wState Property

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

JavaScript, JScript

function Test()
{
  // Select the Android device
  Mobile.SetCurrent("MyDevice");

  // Obtain the required ToggleButton
  var p = Mobile.Device().Process("com.example.myapp");
  var Toggle = p.RootLayout("").Layout("layoutTop").Layout("layout1").ToggleButton("toggle1");
  
  // Obtain the state of ToggleButton
  var State = Toggle.wState;
  
  // Post the state to the log
  Log.Message(State);
}

Python

def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")

  # Obtain the required ToggleButton
  p = Mobile.Device().Process("com.example.myapp")
  Toggle = p.RootLayout("").Layout("layoutTop").Layout("layout1").ToggleButton("toggle1")
  
  # Obtain the state of ToggleButton
  State = Toggle.wState
  
  # Post the state to the log
  Log.Message(State)

VBScript

Sub Test()
  ' Select the Android device
  Call Mobile.SetCurrent("MyDevice")

  ' Obtain the required ToggleButton
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Toggle = p.RootLayout("").Layout("layoutTop").Layout("layout1").ToggleButton("toggle1")
  
  ' Obtain the state of ToggleButton
  State = Toggle.wState
  
  ' Post the state to the log
  Call Log.Message(State)
End Sub

DelphiScript

procedure Test();
var
  p, Toggle, State : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');

  // Obtain the required ToggleButton
  p := Mobile.Device.Process('com.example.myapp');
  Toggle := p.RootLayout('').Layout('layoutTop').Layout('layout1').ToggleButton('toggle1');
  
  // Obtain the state of ToggleButton
  State := Toggle.wState;
  
  // Post the state to the log
  Log.Message(State);
end;

C++Script, C#Script

function Test()
{
  // Select the Android device
  Mobile["SetCurrent"]("MyDevice");

  // Obtain the required ToggleButton
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var Toggle = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1")["ToggleButton"]("toggle1");
  
  // Obtain the state of ToggleButton
  var State = Toggle["wState"];
  
  // Post the state to the log
  Log["Message"](State);
}

Using From Keyword Testing

This topic explains how to setermine the state of the toggle button control in scripts. You can use the described property in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.

See Also

Working With Android Toggle Button Controls
wState Property (Mobile Controls)

Highlight search results