Clicking a Button

Applies to TestComplete 14.40, last modified on April 22, 2021

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

There are several ways to click a button in an application:

  • Use the Click or ClickButton actions. These actions simulate a single click on a button. Here is an example of how to perform a click via these actions:

    JavaScript, JScript

    myButton.Click();

    myButton.ClickButton();

    Python

    myButton.Click()
    myButton.ClickButton()

    VBScript

    myButton.Click

    myButton.ClickButton

    DelphiScript

    myButton.Click;

    myButton.ClickButton;

    C++Script, C#Script

    myButton["Click"]();

    myButton["ClickButton"]();

  • You can click a button by simulating keystrokes that represent an access key. An access key is an underlined symbol within the button caption. It permits a click of a button by pressing the Alt key in combination with the assigned access key. For example, if the underlined symbol is F, you should simulate pressing the Alt+F key combination (for detailed information about simulating keystrokes, see the Simulating Keystrokes topic). The example below simulates an access key:

    JavaScript, JScript

    myButton.Keys("~f");

    Python

    myButton.Keys("~f")

    VBScript

    myButton.Keys "~f"

    DelphiScript

    myButton.Keys('~f');

    C++Script, C#Script

    myButton["Keys"]("~f");

  • You can click a button by setting the focus to it (for example, by using the Tab key) and simulating the Space key press. For detailed information on how to simulate keystrokes, see the Simulating Keystrokes topic. Here is an example:

    JavaScript, JScript

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

    Python

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

    VBScript

    ...
    Sys.Keys "[Tab][Tab][Tab]"
    Sys.Keys "[X32]"
    ...

    DelphiScript

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

    C++Script, C#Script

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

Note: You can only click a button if it is enabled. To get information on how to determine a button’s state, see the Checking a Button's State topic.

See Also

Working With Button Controls
Checking a Button's State
Click Action
ClickButton Action (Button Controls)
Simulating Keystrokes

Highlight search results