Checking the Toolbar Buttons' Type in Desktop Windows Applications

Applies to TestComplete 15.69, last modified on November 13, 2024

Toolbars can contain different types of buttons: usual push buttons, toggle buttons, drop-down buttons, separators and so on. You may need to know the button type in order to know what actions you can perform over it. This topics describes how you can determine the type of toolbar buttons from tests.

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

The Win32ToolBar, StripToolBar and WPFToolBar objects, which provide scripting access to various kinds of toolbar controls, contain special properties that let you determine the toolbar button type:

  • wIsCheckButton returns True if the button is a toggle button (that is, it can be checked or unchecked).

  • wIsDropDownButton returns True if the button has a drop-down menu.

  • wIsSeparatorButton returns True if the button is a separator.

All of these properties have the Item parameter, which specifies the desired toolbar button (see Addressing Toolbar Buttons in Desktop Windows Applications). The Win32ToolBar object properties have an extra ByPosition parameter that is used when the button is specified by index or IDs.

All of these properties return False for standard push buttons.

The following example iterates through the toolbar buttons in Internet Explorer, determines the type of each button and posts it to the test log.

JavaScript, JScript

function Main ()
{
  // Obtain the IE process and toolbar
  Browsers.Item(btIExplorer).Run("about:blank");
  var browser = Sys.Browser("iexplore");
  var toolbar = browser.FindChild("WndCaption", "Command Bar", 20);

  LogButtonTypes(toolbar);
}

function LogButtonTypes (ToolBar)
{
  for (var i=0; i<ToolBar.wButtonCount; i++)
  {
    if (ToolBar.wIsCheckButton(i, true))
      Log.Message("The toolbar button " + i +
                   " (" + ToolBar.wButtonText(i, true) + ") is a toggle button.")

    else if (ToolBar.wIsDropDownButton(i, true))
      Log.Message("The toolbar button " + i +
                  " (" + ToolBar.wButtonText(i, true) + ") is a drop-down button.")

    else if (ToolBar.wIsSeparatorButton(i, true))
      Log.Message("The toolbar button " + i + " is a separator.")

    else
      Log.Message("The toolbar button " + i +
                  " (" + ToolBar.wButtonText(i, true) + ") is a push button.")
  }
}

Python

def Main ():
  # Obtain the IE process and toolbar
  Browsers.Item[btIExplorer].Run("about:blank")
  browser = Sys.Browser("iexplore")
  toolbar = browser.FindChild("WndCaption", "Command Bar", 20)

  LogButtonTypes(toolbar)

def LogButtonTypes (ToolBar):
  for i in range(0, ToolBar.wButtonCount-1):
    if ToolBar.wIsCheckButton[i, True]:
      Log.Message("The toolbar button " + i + \
                   " (" + ToolBar.wButtonText[i, True] + ") is a toggle button.")

    elif (ToolBar.wIsDropDownButton[i, True]):
      Log.Message("The toolbar button " + i + \
                  " (" + ToolBar.wButtonText[i, True] + ") is a drop-down button.")

    elif (ToolBar.wIsSeparatorButton[i, True]):
      Log.Message("The toolbar button " + i + " is a separator.")

    else:
      Log.Message("The toolbar button " + i + \
                  " (" + ToolBar.wButtonText[i, True] + ") is a push button.")

VBScript

Sub Main
  Dim browser, toolbar
  ' Obtain the IE process and toolbar
  Browsers.Item(btIExplorer).Run "about:blank"
  Set browser = Sys.Browser("iexplore")
  Set toolbar = browser.FindChild("WndCaption", "Command Bar", 20)

  LogButtonTypes(toolbar)
End Sub

Sub LogButtonTypes (ToolBar)
  Dim i

  For i = 0 To ToolBar.wButtonCount-1
    If ToolBar.wIsCheckButton(i, True) Then
      Log.Message("The toolbar button " & i & _
                   " (" & ToolBar.wButtonText(i, True) & ") is a toggle button.")

    ElseIf ToolBar.wIsDropDownButton(i, True) Then
      Log.Message("The toolbar button " & i & _
                  " (" & ToolBar.wButtonText(i, True) & ") is a drop-down button.")

    ElseIf (ToolBar.wIsSeparatorButton(i, True)) Then
      Log.Message("The toolbar button " & i & " is a separator.")

    Else
      Log.Message("The toolbar button " & i & _
                  " (" & ToolBar.wButtonText(i, True) & ") is a push button.")
    End If
  Next
End Sub

DelphiScript

procedure LogButtonTypes (ToolBar);
var i : OleVariant;
begin
  for i := 0 to ToolBar.wButtonCount-1 do
  begin
    if ToolBar.wIsCheckButton[i, true] then
      Log.Message('The toolbar button ' + aqConvert.VarToStr(i) +
                  ' (' + ToolBar.wButtonText[i, true] + ') is a toggle button.')

    else if ToolBar.wIsDropDownButton[i, true] then
      Log.Message('The toolbar button ' + aqConvert.VarToStr(i) +
                  ' (' + ToolBar.wButtonText[i, true] + ') is a drop-down button.')

    else if ToolBar.wIsSeparatorButton[i, true] then
      Log.Message('The toolbar button ' + aqConvert.VarToStr(i) + ' is a separator.')

    else
      Log.Message('The toolbar button ' + aqConvert.VarToStr(i) +
                  ' (' + ToolBar.wButtonText[i, true] + ') is a push button.')
  end;
end;

procedure Main;

var browser, toolbar : OleVariant;
begin
  // Obtain the IE process and toolbar
  Browsers.Item[btIExplorer].Run('about:blank');
  browser := Sys.Browser('iexplore');
  toolbar := browser.FindChild('WndCaption', 'Command Bar', 20);

  LogButtonTypes(toolbar);

end;

C++Script, C#Script

function Main ()
{

  // Obtain the IE process and toolbar
  Browsers["Item"](btIExplorer)["Run"]("about:blank");
  var browser = Sys["Browser"]("iexplore");
  var toolbar = browser["FindChild"]("WndCaption", "Command Bar", 20);

  LogButtonTypes(toolbar);
}

function LogButtonTypes (ToolBar)
{

  for (var i=0; i<ToolBar["wButtonCount"]; i++)
  {
    if (ToolBar["wIsCheckButton"](i, true))
      Log["Message"]("The toolbar button " + i +
                   " (" + ToolBar["wButtonText"](i, true) + ") is a toggle button.")

    else if (ToolBar["wIsDropDownButton"](i, true))
      Log["Message"]("The toolbar button " + i +
                  " (" + ToolBar["wButtonText"](i, true) + ") is a drop-down button.")

    else if (ToolBar["wIsSeparatorButton"](i, true))
      Log["Message"]("The toolbar button " + i + " is a separator.")

    else
      Log["Message"]("The toolbar button " + i +
                  " (" + ToolBar["wButtonText"](i, true) + ") is a push button.")
  }
}

See Also

Working With Toolbars in Desktop Windows Applications
Checking the Toolbar Buttons' State in Desktop Windows Applications

Highlight search results