Working With iOS Picker View Controls - Basic Concepts

Applies to TestComplete 15.62, last modified on March 19, 2024

General Notes

With TestComplete, you can simulate actions over picker view controls in iOS applications. Picker view controls are associated with the iOS PickerView object, and TestComplete uses various methods provided by this object (such as TouchItem, LongTouchItem and other). The PickerView iOS object’s properties allow you to retrieve data from the picker views and check their item’s properties. For instance, the wSelectedItem property returns the index of the selected item, and so on. For more information on available actions, see the object description and Working With iOS Picker View Controls.

Addressing Items and Wheels

The section below describes how to specify picker view items in your tests:

Using Item Indexes and Names

It is possible to specify an item by its name or index. In most cases, you specify an item by its name in the following way:

pickerview.TouchItem("Item1", 0)    // Touch an item

If an item does not have a name, you can specify it using its index (in other words, its position). Indexes are zero-based: the first item of each wheel of the picker view has index 0, the second - 1, and so on. The total number of items is specified by the wItemCount property. The last item has index wItemCount - 1.

To address a wheel different from the first, you need to specify the wheel index, as well. The total number of wheels is specified by the wWheelCount property. The last wheel has index wWheelCount - 1.

For instance, the script below simulates a touch on the fifth item of the second wheel:

JavaScript, JScript

function Test()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Obtain the PickerView object
  var p = Mobile.Device().Process("SampleApp");
  var pickerview = p.Window(3).PickerView();

  // Touch PickerView item
  pickerview.TouchItem(4, 1);
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the PickerView object 
  p = Mobile.Device().Process("SampleApp")
  pickerview = p.Window(3).PickerView()

  # Touch PickerView item
  pickerview.TouchItem(4, 1)

VBScript

Sub Test()
  Dim p, pickerview
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the PickerView object
  Set p = Mobile.Device.Process("SampleApp")
  Set pickerview = p.Window(2).PickerView

  ' Touch PickerView item
  Call pickerview.TouchItem(4, 1)
End Sub

DelphiScript

procedure Test();
var
  p, pickerview;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the PickerView object
  p := Mobile.Device.Process('SampleApp');
  pickerview := p.Window(3).PickerView;

  // Touch PickerView item
  pickerview.TouchItem(4, 1);
end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");
  // Obtain the PickerView object
  var p = Mobile["Device"].Process("SampleApp");
  var pickerview = p["Window"](3)["PickerView"]();

  // Touch PickerView item
  pickerview["TouchItem"](4, 1);
}

Working With PickerView Items

TestComplete recognizes items of PickerView controls as objects. It displays appropriate test objects as child nodes of the PickerView node in the object hierarchy.

We do not recommend working with picker view items through these child objects. Use appropriate methods and properties of the PickerView test object instead.

Specifics of Working With PickerView Controls

During the playback, the picker view iOS objects use the following principles for simulating user actions:

  • In properties and methods of the picker view objects, you can specify the desired picker view item using its index or caption. When specifying item caption, you can use wildcards (* and ?) or regular expressions. The asterisk (*) corresponds to a string of any length (including an empty string), the question mark corresponds to any single character (including none). To specify more complicated parts of a caption, use regular expressions.

    In addition, TestComplete can treat the item captions as case-sensitive or case-insensitive depending on the Use case-sensitive parameters project setting (you can change it on the Properties page of your project’s editor).

  • If the target picker view item is out of the device’s screen bound, it cannot be displayed in the Object Browser panel. As a result, you cannot perform a touch on the item. To do this, you should use internal methods of the picker view object (TouchItem, LongTouchItem and so on). In this case, the control is automatically scrolled to the specified item and simulates the desired action.

See Also

Working With iOS Picker View Controls
Object-Specific Tasks
iOS PickerView Support
Supported Controls

Highlight search results