Determining a Check Box's State

Applies to TestComplete 12.60, last modified on September 17, 2018
Using wState Property

To determine the state of a check box control, use the wState property of the Android CheckBox object that TestComplete associates with that control. If the check box is checked, this property returns 1 or True; otherwise - 0 or False. The following example determines the state of the check box control and posts it to the log:

JavaScript, JScript

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

  // Obtain the check box object
  var p = Mobile.Device().Process("com.example.myapp");
  var Checkbox = p.RootLayout("").Layout("layoutTop").Layout("layout1").Checkbox("check1");
  
  // Check the state of the check box
  State = Checkbox.wState;

  // Post the state to the log
  Log.Message(State);
}

Python

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

  # Obtain the check box object
  p = Mobile.Device().Process("com.example.myapp")
  Checkbox = p.RootLayout("").Layout("layoutTop").Layout("layout1").Checkbox("check1")
  
  # Check the state of the check box
  State = Checkbox.wState

  # Post the state to the log
  Log.Message(State)

VBScript

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

  ' Obtain the check box object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Checkbox = p.RootLayout("").Layout("layoutTop").Layout("layout1").CheckBox("check1")
  
  ' Check the state of the check box
  State = Checkbox.wState

  ' Post the state to the log
  Call Log.Message(State)
End Sub

DelphiScript

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

  // Obtain the check box object
  p := Mobile.Device.Process('com.example.myapp');
  Checkbox := p.RootLayout('').Layout('layoutTop').Layout('layout1').Checkbox('check1');
  
  // Check the state of the check box
  State := Checkbox.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 check box object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var Checkbox = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1")["Checkbox"]("check1");
  
  // Check the state of the check box
  State = Checkbox["wState"];

  // Post the state to the log
  Log["Message"](State);
}

Simulating Actions From Keyword Tests

This topic explains how to determine the state of the checkbox 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 Check Box Controls
wState Property (Mobile Controls)

Highlight search results