Selecting and Clearing Check Boxes in Desktop Windows Applications

Applies to TestComplete 15.47, last modified on January 20, 2023

Note: To learn how to simulate user actions over check box controls in web applications, see Working With Check Box Controls in Web Applications.

While testing check box 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.

A check box is a toggle that is used to choose options. If the specified option is on, the corresponding check box is checked; otherwise, it is unchecked. Selecting and clearing check boxes can be done in the following ways:

  • You can specify a check box state by using the ClickButton action. ClickButton is a specific action of the Win32CheckBox object. While the Click action performs one click over an object, the ClickButton action performs a series of clicks, which puts the control to the desired state. This state is specified by the State parameter of the ClickButton action. This parameter has three values that specify three different states you can set. If the State parameter corresponds to the current check box state, ClickButton performs no action. The following code snippet sets a check box to the unchecked state:

    JavaScript, JScript

    myCheckBox.ClickButton(cbUnchecked);

    Python

    myCheckBox.ClickButton(cbUnchecked)

    VBScript

    myCheckBox.ClickButton cbUnchecked

    DelphiScript

    myCheckBox.ClickButton(cbUnchecked);

    C++Script, C#Script

    myCheckBox["ClickButton"](cbUnchecked);

  • You can select or clear a check box by assigning the needed value to the wState property. This property belongs to the Win32CheckBox object and allows you to determine or set the check box state. For more information on determining the current control's state, see the Determining a Check Box's State in Desktop Windows Applications topic. Here is an example of how to obtain and modify the state of a check box:

    JavaScript, JScript

    ...
    // Select the check box
    myCheckBox.wState = cbChecked;

    // Post the current check box state to the log
    Log.Message(myCheckBox.wState);

    // Clear the check box
    myCheckBox.wState = cbUnchecked;
    ...

    Python

    ...
    # Select the check box
    myCheckBox.wState = cbChecked
    
    # Post the current check box state to the log
    Log.Message(myCheckBox.wState)
    
    # Clear the check box
    myCheckBox.wState = cbUnchecked
    ...

    VBScript

    ...
    ' Select the check box
    myCheckBox.wState = cbChecked

    ' Post the current check box state to the log
    Log.Message(myCheckBox.wState)

    ' Clear the check box
    myCheckBox.wState = cbUnchecked
    ...

    DelphiScript

    ...
    // Select the check box
    myCheckBox.wState := cbChecked;

    // Post the current check box state to the log
    Log.Message(myCheckBox.wState);

    // Clear the check box
    myCheckBox.wState := cbUnchecked;
    ...

    C++Script, C#Script

    ...
    // Select the check box
    myCheckBox["wState"] = cbChecked;

    // Post the current check box state to the log
    Log["Message"](myCheckBox.wState);

    // Clear the check box
    myCheckBox["wState"] = cbUnchecked;
    ...

  • You can toggle check box states by using the Click action. This action belongs to the Win32CheckBox object and allows you to perform a single click over a control. Here is an example:

    JavaScript, JScript

    myCheckBox.Click();

    Python

    myCheckBox.Click()

    VBScript

    myCheckBox.Click

    DelphiScript

    myCheckBox.Click;

    C++Script, C#Script

    myCheckBox["Click"]();

  • You can switch check box states by simulating keystrokes. You should choose the needed check box control by simulating the Tab key or arrow keys. Then you can change the current check box state by simulating the Space key. For detailed information on how to simulate keystrokes, see the Simulating Keystrokes topic. The following code snippet demonstrates how to toggle check box states:

    JavaScript, JScript

    ...
    myCheckBox.Keys("[Tab][Tab]");
    myCheckBox.Keys("[X32]");
    ...

    Python

    ...
    myCheckBox.Keys("[Tab][Tab]")
    myCheckBox.Keys("[X32]")
    ...

    VBScript

    ...
    myCheckBox.Keys "[Tab][Tab]"
    myCheckBox.Keys "[X32]"
    ...

    DelphiScript

    ...
    myCheckBox.Keys('[Tab][Tab]');
    myCheckBox.Keys('[X32]');
    ...

    C++Script, C#Script

    ...
    myCheckBox["Keys"]("[Tab][Tab]");
    myCheckBox["Keys"]("[X32]");
    ...

See Also

Working With Check Box Controls in Desktop Windows Applications
Determining a Check Box's State in Desktop Windows Applications
Simulating Keystrokes
Click Action
ClickButton Action (CheckBox and ToggleButton Controls)
wState Property (CheckBox and ToggleButton Controls)
Working With Check Box Controls in Web Applications

Highlight search results