Applies to TestComplete 14.50, last modified on August 05, 2020

Before clicking a button, you may need to know whether it is enabled or not. If the button is disabled, an error will occur in your test.

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.

You can use the properties and methods of the Win32Button object to get information about the current button control. The Enabled property allows you to determine whether the current button control accepts user input. If the button is enabled, this property returns True; otherwise, False. The following example demonstrates how to check the button state:

JavaScript, JScript

...
if (MyButton.Enabled)
  MyButton.Click();
else
  Log.Message("The button is disabled.");
...

Python

...
if MyButton.Enabled:
  MyButton.Click()
else:
  Log.Message("The button is disabled.")
...

VBScript

...
If MyButton.Enabled Then
  MyButton.Click
Else
  Log.Message("The button is disabled.")
End If
...

DelphiScript

...
if MyButton.Enabled then
  MyButton.Click
else
  Log.Message('The button is disabled.');
...

C++Script, C#Script

...
if (MyButton["Enabled"])
  MyButton["Click"]();
else
  Log["Message"]("The button is disabled.");
...

See Also

Working With Button Controls
Win32 Button Support
Enabled Property

Highlight search results