Determining a Radio Button's State in Desktop Windows Applications

Applies to TestComplete 15.45, last modified on December 01, 2022

Radio button controls provide users with the ability to make a single choice from a number of alternative options. So, in some cases, you may need to know whether the current radio button is selected or not (for example, if you want your test to select various sets of options depending on the already selected buttons).

While testing radio button controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

You can use the wChecked property to determine the state of the needed radio button control. If the radio button is selected, the wChecked property returns True; otherwise, False. The following code demonstrates how to obtain information about the state of the current radio button:

JavaScript, JScript

...
if (RB1.wChecked)
  Log.Message("This option is selected");
else
  Log.Message("This option is not selected");
...

Python

... 
if RB1.wChecked:
  Log.Message("This option is selected")
else:
  Log.Message("This option is not selected")
...

VBScript

...
If RB1.wChecked Then
  Log.Message "This option is selected"
Else
  Log.Message "This option is not selected"
End If
...

DelphiScript

...
if RB1.wChecked then
  Log.Message('This option is selected')
else
  Log.Message('This option is not selected')
...

C++Script, C#Script

...
if (RB1["wChecked"])
  Log.Message("This option is selected")
else
  Log.Message("This option is not selected")
...

See Also

Working With Radio Button Controls in Desktop Windows Applications
wChecked Property (RadioButton Controls)

Highlight search results