Determining the Number of Tab Bar Items

Applies to TestComplete 15.40, last modified on July 05, 2022

Tab bar controls in iOS applications usually have a number of tab bar items. When working with tab bar controls, you may need to determine the number of items the control contains.

This topic describes how to get the number of tab bar items from tests.

Using the wTabCount Property

To determine the number of tab bar items, use the wTabCount property of the iOS TabBar test object that TestComplete automatically associates with your tab bar control. This property returns the total number of items of the tab bar control.

The following example obtains the number of tab bar items of a control and posts it to the test log:

JavaScript, JScript

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

  // Obtain the TabBar object
  var p = Mobile.Device().Process("SampleApp");
  var tabBar = p.Window(0).TabBar();

  // Get the number of tab bar's items and post it to the test log
  var count = tabBar.wTabCount;
  Log.Message("The number of tab bar items is " + aqConvert.VarToStr(count));
}

Python

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

  # Obtain the TabBar object
  p = Mobile.Device().Process("SampleApp")
  tabBar = p.Window(0).TabBar()

  # Get the number of tab bar's items and post it to the test log
  count = tabBar.wTabCount
  Log.Message("The number of tab bar items is " + str(count))

VBScript

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

  ' Obtain the TabBar object
  Set p = Mobile.Device.Process("SampleApp")
  Set tabBar = p.Window(0).TabBar

  ' Get the number of tab bar's items and post it to the test log
  count = tabBar.wTabCount
  Log.Message("The number of tab bar items is " + aqConvert.VarToStr(count))
End Sub

DelphiScript

procedure Test();
var p, tabBar, count;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');

  // Obtain the TabBar object
  p := Mobile.Device.Process('SampleApp');
  tabBar := p.Window(0).TabBar;

  // Get the number of tab bar's items and post it to the test log
  count := tabBar.wTabCount;
  Log.Message('The number of tab bar items is ' + aqConvert.VarToStr(count));
end;

C++Script, C#Script

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

  // Obtain the TabBar object
  var p = Mobile["Device"]["Process"]("SampleApp");
  var tabBar = p["Window"](0)["TabBar"]();

  // Get the number of tab bar's items and post it to the test log
  var count = tabBar["wTabCount"];
  Log["Message"]("The number of tab bar items is " + aqConvert.VarToStr(count));
}

Obtaining Tab Bar Items Number From Keyword Tests

To get the number of tab bar control’s items from keyword tests, use the On-Screen Action or Call Object Method operation to access the properties described above. See Getting and Setting Object Property Values.

See Also

Working With iOS TabBar Controls
wTabCount Property (Mobile Controls)
Selecting Tab Bar Items

Highlight search results