Checking a Button's State

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

Before touching a button in an iOS application, you may need to check whether the button is enabled.

Getting the Enabled Property

To check whether a button control is enabled, use the Enabled property of the iOS 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 a button's control state:

JavaScript, JScript

function Test()
{

  // Select the mobile device
  Mobile.SetCurrent("iPhone");

  // Obtain the button object
  var p = Mobile.Device().Process("SampleApp");
  var button = p.Window(0).Button("Simple Button");

  // Check whether the button is enabled
  if (button.Enabled)
  {
    // Simulate user actions over the button
    …
  }

}

Python

def Test():

  # Select the mobile device
  Mobile.SetCurrent("iPhone")

  # Obtain the button object
  p = Mobile.Device().Process("SampleApp")
  button = p.Window(0).Button("Simple Button")

  # Check whether the button is enabled
  if button.Enabled:
    # Simulate user actions over the button
    ...

VBScript

Sub Test

  ' Select the mobile device
  Mobile.SetCurrent("iPhone")

  ' Obtain the button object
  Set p = Mobile.Device.Process("SampleApp")
  Set button = p.Window(0).Button("Simple Button")

  ' Check whether the button is enabled
  If button.Enabled Then
    ' Simulate user actions over the button
    …
  End If

End Sub

DelphiScript

procedure Test();
var p, button;
begin

  // Select the mobile device
  Mobile.SetCurrent('iPhone');

  // Obtain the button object
  p := Mobile.Device.Process('SampleApp');
  button := p.Window(0).Button('Simple Button');

  // Check whether the button is enabled
  if button.Enabled then
  begin
    // Simulate user actions over the button
    …
  end;

end;

C++Script, C#Script

function Test()
{

  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");

  // Obtain the button object
  var p = Mobile["Device"]["Process"]("SampleApp");
  var button = p["Window"](0)["Button"]("Simple Button");

  // Check whether the button is enabled
  if (button["Enabled"])
  {
    // Simulate user actions over the button
    …
  }

}

Checking the State From Keyword Tests

To check whether a button control is enabled, you can use the If Object operation. You can also check the value of the described Enabled property by using various keyword test operations.

See Also

Working With iOS Button Controls
Enabled Property
Touching a Button

Highlight search results