Getting Tab Bar Items' Captions

Applies to TestComplete 14.93, last modified on October 12, 2021

Tab bar items of tab bar controls in iOS applications usually have a caption that describes the application view to which they provide access. This topic describes how to obtain the tab bar control’s items captions from tests.

Using wTabCaption Property

To obtain the caption of a tab bar item, use the wTabCaption property of the iOS TabBar object that TestComplete associates with the tab bar control. This property returns the caption of the tab bar item specified by its index (zero-based).

The following example gets the captions of the tab bar items and posts them 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();

  // Iterate through tab bar items and post their captions to the test log
  for (var i = 0; i < tabBar.wTabCount; i++)
    Log.Message(tabBar.wTabCaption(i));
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  
  # Obtain the TabBar object
  p = Mobile.Device().Process("SampleApp")
  tabBar = p.Window(0).TabBar()

  # Iterate through tab bar items and post their captions to the test log
  for i in range(0, tabBar.wTabCount):
    Log.Message(tabBar.wTabCaption[i])

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

  ' Iterate through tab bar items and post their captions to the test log
  For i = 0 To tabBar.wTabCount - 1
    Log.Message(tabBar.wTabCaption(i))
  Next
End Sub

DelphiScript

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

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

  // Iterate through tab bar items and post their captions to the test log
  for i := 0 to tabBar.wTabCount - 1 do
    Log.Message(tabBar.wTabCaption(i));
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"]();

  // Iterate through tab bar items and post their captions to the test log
  for (var i = 0; i < tabBar["wTabCount"]; i++)
    Log["Message"](tabBar["wTabCaption"](i));
}

Obtaining Captions From Keyword Tests

To get a tab bar item’s caption 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
wTabCaption Property (Specific to iOS TabBar Controls)
Selecting Tab Bar Items

Highlight search results