Determining a Radio Button's State

Applies to TestComplete 14.92, last modified on September 16, 2021
Getting wChecked Property

To determine the state of a radio button control, use the wChecked property of the Android RadioButton object that TestComplete associates with that control. If the radio button is selected, the wChecked property returns True; otherwise, False. The following example demonstrates how to obtain information about the state of the radio button control:

JavaScript, JScript

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

  // Obtain the RadioButton object
  var p = Mobile.Device().Process("com.example.myapp");
  var l = p.RootLayout("").Layout("layoutTop").Layout("layout1");
  var Radio = l.RadioGroup("radiogroup1").RadioButton("radio1");
   
  // Check whether RadioButton is checked
  if (Radio.wChecked)
    // Post the message to the log
    Log.Message("This option is selected");
  else
    Log.Message("This option is not selected");
}

Python

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

  # Obtain the RadioButton object
  p = Mobile.Device().Process("com.example.myapp")
  l = p.RootLayout("").Layout("layoutTop").Layout("layout1")
  Radio = l.RadioGroup("radiogroup1").RadioButton("radio1")
   
  # Check whether RadioButton is checked
  if (Radio.wChecked):
    # Post the message to the log
    Log.Message("This option is selected")
  else:
    Log.Message("This option is not selected")

VBScript

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

  ' Obtain the RadioButton object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set l = p.RootLayout("").Layout("layoutTop").Layout("layout1")
  Set Radio = l.RadioGroup("radiogroup1").RadioButton("radio1")

  ' Check whether RadioButton is checked
  If Radio.wChecked Then
    ' Post the message to the log
    Log.Message "This option is selected"
  Else
    Log.Message "This option is not selected"
  End If
End Sub

DelphiScript

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

  // Obtain the RadioButton object
  p := Mobile.Device.Process('com.example.myapp');
  l := p.RootLayout('').Layout('layoutTop').Layout('layout1');
  Radio := l.RadioGroup('radiogroup1').RadioButton('radio1');
  
  // Check whether RadioButton is checked
  if Radio.wChecked then
    // Post the message to the log
    Log.Message('This option is selected')
  else
    Log.Message('This option is not selected')
end;

C++Script, C#Script

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

  // Obtain the RadioButton object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var l = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1");
  var Radio = l["RadioGroup"]("radiogroup1")["RadioButton"]("radio1")
   
  // Check whether RadioButton is checked
  if (Radio["wChecked"])
    // Post the message to the log
    Log["Message"]("This option is selected")
  else
    Log["Message"]("This option is not selected")
}

Simulating Actions From Keyword Tests

This topic explains how to determine the state of the radio 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 Radio Button Controls
wChecked Property (Mobile Controls)

Highlight search results