Checking a Button's State

Applies to TestComplete 14.10, last modified on June 5, 2019
Getting the Enabled Property

To check whether the button control is enabled, use the Enabled property of the Android Button object that TestComplete associates with that control. If the button is enabled, this property returns True; otherwise, False. The following example demonstrates how to check the button control state:

JavaScript, JScript

function Test()
{
  // Select the Android device
  Mobile.SetCurrent("MyDevice");

  // Obtain the button object
  var p = Mobile.Device().Process("com.example.myapp");
  var Button = p.RootLayout("").Layout("layoutTop").Layout("layout1").Button("button1");
  
  // Check whether the button is enabled
  if (Button.Enabled)
    // Post a message to the log
    Log.Message("The button is enabled.");
}

Python

def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")

  # Obtain the button object
  p = Mobile.Device().Process("com.example.myapp")
  Button = p.RootLayout("").Layout("layoutTop").Layout("layout1").Button("button1")
  
  # Check whether the button is enabled
  if Button.Enabled:
    # Post a message to the log
    Log.Message("The button is enabled.")

VBScript

Sub Test()
  ' Select the Android device
  Mobile.SetCurrent("MyDevice")

  ' Obtain the button object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set Button = p.RootLayout("").Layout("layoutTop").Layout("layout1").Button("button1")
  
  ' Check whether the button is enabled
  If Button.Enabled Then
    ' Post a message to the log
    Call Log.Message("The button is enabled.")
  End If
End Sub

DelphiScript

procedure Test();
var
  p, Button : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');

  // Obtain the button object
  p := Mobile.Device.Process('com.example.myapp');
  Button := p.RootLayout('').Layout('layoutTop').Layout('layout1').Button('button1');
  
  // Check whether the button is enabled
  if (Button.Enabled) then
    // Post a message to the log
    Log.Message('The button is enabled.');
end;

C++Script, C#Script

function Test()
{
  // Select the Android device
  Mobile["SetCurrent"]("MyDevice");

  // Obtain the button object
  var p = Mobile["Device"].Process("com.example.myapp");
  var Button = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout1")["Button"]("button1");
  
  // Check whether the button is enabled
  if (Button["Enabled"])
    // Post a message to the log
    Log["Message"]("The button is enabled.");
}

Simulating Actions From Keyword Tests

This topic explains how to check if the control is enabled for the button control in scripts. You can use the described property in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.

See Also

Working With Android Button Controls
Enabled Property
Touching a Button

Highlight search results