Selecting and Clearing Check Boxes

Applies to TestComplete 15.0, last modified on November 17, 2021
Simulating Touch Action

To simulate the touch on a check box control, use the Touch action of the Android CheckBox object that TestComplete associates with that control. This action performs a single short touch on the control. The following example performs a touch on the specified check box control:

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");
  
  // Touch the check box
  Checkbox.Touch();
}

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")
  
  # Touch the check box
  Checkbox.Touch()

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

  ' Touch the check box
  Checkbox.Touch()
End Sub

DelphiScript

procedure Test();
var
  p, Checkbox : 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');
  
  // Touch the check box
  Checkbox.Touch;
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");
  
  // Touch the check box
  Checkbox["Touch"]();
}

Simulating CheckButton Action

To specify the check box state after the touch, use the CheckButton action. This action performs a series of touches, which put the control to the state specified by the State parameter. If this parameter corresponds to the current check box state, no action is performed. The following example sets the check box control to the unchecked state:

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");
  
  // Set the check box status to "unchecked"
  Checkbox.CheckButton(cbUnchecked);
}

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")
  
  # Set the check box status to "unchecked"
  Checkbox.CheckButton(cbUnchecked)

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

  ' Set the check box status to "unchecked"
  Checkbox.CheckButton(cbUnchecked)
End Sub

DelphiScript

procedure Test();
var
  p, Checkbox : 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');
  
  // Set the check box status to "unchecked"
  Checkbox.CheckButton(cbUnchecked);
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");
  
  // Set the check box status to "unchecked"
  Checkbox["CheckButton"](cbUnchecked);
}

Assigning wState Property

To select or clear a check box, assign the value to the wState property. Assigning the value is not posted to the log. The following example modifies the state of a check box:

JavaScript, JScript

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

  // Obtain the required check box
  var p = Mobile.Device().Process("com.example.myapp").RootLayout("");
  var Checkbox = p.Layout("layoutTop").Layout("layout2").CheckBox("check1");
  
  // Select the check box
  Checkbox.wState = cbChecked;
  
  // Post the current check box state to the log
  Log.Message(Checkbox.wState);

  // Clear the check box
  Checkbox.wState = cbUnchecked;
}

Python

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

  # Obtain the required check box
  p = Mobile.Device().Process("com.example.myapp").RootLayout("")
  Checkbox = p.Layout("layoutTop").Layout("layout2").CheckBox("check1")
  
  # Select the check box
  Checkbox.wState = cbChecked
  
  # Post the current check box state to the log
  Log.Message(Checkbox.wState)

  # Clear the check box
  Checkbox.wState = cbUnchecked

VBScript

Sub Test()

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

  ' Obtain the required check box
  Set p = Mobile.Device.Process("com.example.myapp").RootLayout("")
  Set Checkbox = p.Layout("layoutTop").Layout("layout2").CheckBox("check1")
  
  ' Select the check box
  Checkbox.wState = cbChecked
  
  ' Post the current check box state to the log
  Call Log.Message(Checkbox.wState)

  ' Clear the check box
  Checkbox.wState = cbUnchecked
End Sub

DelphiScript

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

  // Obtain the required check box
  p := Mobile.Device.Process('com.example.myapp').RootLayout('');
  Checkbox := p.Layout('layoutTop').Layout('layout2').CheckBox('check1');
  
  // Select the check box
  Checkbox.wState := cbChecked;
  
  // Post the current check box state to the log
  Log.Message(Checkbox.wState);

  // Clear the check box
  Checkbox.wState := cbUnchecked;
end;

C++Script, C#Script

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

  // Obtain the required check box
  var p = Mobile["Device"]["Process"]("com.example.myapp")["RootLayout"]("")
  var Checkbox = p["Layout"]("layoutTop")["Layout"]("layout2")["CheckBox"]("check1")
  
  // Select the check box
  Checkbox["wState"] = cbChecked;
  
  // Post the current check box state to the log
  Log["Message"](Checkbox.wState);

  // Clear the check box
  Checkbox["wState"] = cbUnchecked;
}

Simulating Actions From Keyword Tests

This topic explains how to select or clear the checkbox control in scripts. You can use the described properties and methods 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
Determining a Check Box's State
CheckButton Action (Mobile Controls)
Touch Action (Mobile Objects)
wState Property (Mobile Controls)

Highlight search results