Selecting Tab Bar Items

Applies to TestComplete 15.68, last modified on October 03, 2024

Tab bar controls in iOS applications are usually used to allow a user to switch among a set of application’s views. To switch to a desired view, a user selects an appropriate tab bar item.

When testing iOS applications, before you simulate actions on the controls that belong to the application’s view, you may need to switch to that view by selecting a corresponding tab bar item. This topic describes how to select tab bar items from tests.

Simulating Touch Actions on Tab Bar Items

To select a tab bar item, use the TouchTab or LongTouchTab methods of the iOS TabBar test object TestComplete associates with tab bar controls in iOS applications. These actions simulate a single short or long touch on the tab bar item specified by its index (starting from 0) or caption. If the item is already selected, no actions are performed.

The following sample code selects the first tab bar item of the tab bar control, and then selects a tab with the "Item 1" caption:

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();

  // Select a tab bar item by its index
  tabBar.TouchTab(0);

  // Select a tab bar item by its caption
  tabBar.TouchTab("Item 1");
}

Python

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

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

  # Select a tab bar item by its index
  tabBar.TouchTab(0)

  # Select a tab bar item by its caption
  tabBar.TouchTab("Item 1")

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

  ' Select a tab bar item by its index
  tabBar.TouchTab(0)

  ' Select a tab bar item by its caption
  tabBar.TouchTab("Item 1")
End Sub

DelphiScript

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

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

  // Select a tab bar item by its index
  tabBar.TouchTab(0);

  // Select a tab bar item by its caption
  tabBar.TouchTab('Item 1');
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"]();

  // Select a tab bar item by its index
  tabBar["TouchTab"](0);

  // Select a tab bar item by its caption
  tabBar["TouchTab"]("Item 1");
}

Simulating Touch Actions From Keyword Tests

To select tab bar items from keyword tests, call the methods described above by using the On-Screen Action or Call Object Method operation. See Calling Object Methods.

See Also

Working With iOS TabBar Controls
Determining the Selected Tab Bar Item
TouchTab Method (Mobile Controls)
LongTouchTab Method (Specific to iOS TabBar Controls)

Highlight search results