Message - Unable to perform the action because the control is disabled.

Applies to TestComplete 15.63, last modified on April 23, 2024

TestComplete posts this message to the test log when a test is trying to simulate a mouse click, mouse dragging or some other action over a web control, and the control is disabled at that moment. Since the control is disabled, the operation cannot be performed and TestComplete posts this message to notify you about this.

Typically, to resolve the problem, you need to modify your test so that it simulate actions that enable the control.

To determine the control status, check the state of the control’s Enabled property. This property is provided by TestComplete and is used for all onscreen objects.

Due to the specifics of certain web controls, in some cases, the Enabled property does not reflect their state properly. That is, the property can be True while the control is disabled. To check the control’s state, try using some DOM properties or methods that may indicate the state. The exact property or method to be used depends on the control. See the control documentation or ask the developers for help.

One possible way is to check the className property of a control: some disabled web controls differ from the class name of enabled controls. For example:

  • jQuery UI

    The className property of disabled controls includes the string “ui-state-disabled”.

  • YUI 2

    The className property of disabled controls looks like “control-name-disabled”, for instance, “yui-push-button-disabled”.

  • YUI 3

    The bounding box control element has the className “yui3-[widgetname]-disabled”.

One more possible approach is to create script code that obtains the control and checks its “native” methods and properties. Unfortunately, this code depends on the control type and vendor. For instance, here is how you can check a disabled property of a jQuery button control:

JavaScript, JScript

function CheckDisabled()
{
  // Obtain the test object that corresponds to the control
  var control = Aliases.browser.Page(...).Panel(0).Button(0);
  
  // Obtain the control
  var script = button_element.ownerDocument.Script;
  var button_jquery = script.jQuery(button_element);
  var button = button_jquery.data("button");
  
  // Check the control's properties
  var button_options = button.options;
  if (button_options.disabled)
    ...
  else
    ...
}

Python

def CheckDisabled():
  # Obtain the test object that corresponds to the control
  control = Aliases.browser.Page(...).Panel(0).Button(0);
  
  # Obtain the control
  script = button_element.ownerDocument.Script;
  button_jquery = script.jQuery(button_element);
  button = button_jquery.data("button");
  
  # Check the control's properties
  button_options = button.options;
  if (button_options.disabled):
    #...
  else:
    #...

VBScript

Sub CheckDisabled()
  ' Obtain the test object that corresponds to the control
  Set control = Aliases.browser.Page(...).Panel(0).Button(0)
  
  ' Obtain the control
  Set script = button_element.ownerDocument.Script
  Set button_jquery = script.jQuery(button_element)
  Set button = button_jquery.data("button")
  
  ' Check the control's properties
  Set button_options = button.options
  If button_options.disabled Then
    ...
  Else
    ...
  End If
End Sub

DelphiScript

procedure CheckDisabled();
var  control, script, button_jquery, button, button_options;
begin
  // Obtain the test object that corresponds to the control
  control := Aliases.browser.Page(...).Panel(0).Button(0);
  
  // Obtain the control
  script := button_element.ownerDocument.Script;
  button_jquery := script.jQuery(button_element);
  button := button_jquery.data('button');
  
  // Check the control's properties
  button_options := button.options;
  if button_options.disabled then
    ...
  else
    ...
end;

C++Script, C#Script

function CheckDisabled()
{
  // Obtain the test object that corresponds to the control
  var control = Aliases["browser"]["Page"](...)["Panel"](0)["Button"](0);
  
  // Obtain the control
  var script = button_element["ownerDocument"]["Script"];
  var button_jquery = script["jQuery"](button_element);
  var button = button_jquery["data"]("button");
  
  // Check the control's properties
  var button_options = button["options"];
  if (button_options["disabled"])
    ...
  else
    ...
}

If you experience problems writing checking code, ask your developers for assistance or send a request to SmartBear’s Support Team.

Highlight search results