Getting Picker View Item Text

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

In your tests, you may need to get the text of the picker view item. For example, you may need to check whether the item contains the text before performing certain actions.

Getting Picker View Text

The iOS PickerView object provides a special wItem property that you can use to determine the current text of picker view items. This property has an Item parameter that specifies the desired picker view item. This parameter can use the item's caption or its index. You may also specify the index of the wheel. If it is not specified, the first wheel is used. The property returns the text of the specified item.

The example below posts the text of the second item of the first 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(2).ActionSheet().PickerView();

  // Post PickerView item text to the log
  Log.Message(pickerview.wItem(1, 0))
}

Python

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

  # Post PickerView item text to the log
  Log.Message(pickerview.wItem[1, 0])

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).ActionSheet.PickerView

  ' Post PickerView item text to the log
  Log.Message(pickerview.wItem(1, 0))
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).ActionSheet.PickerView;

  // Post PickerView item text to the log
  Log.Message(pickerview.wItem(1, 0));
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)["ActionSheet"]()["PickerView"]();

  // Post PickerView item text to the log
  pickerview["TouchItem"](1, 0);
}

Getting Picker View Item Text From Keyword Tests

To get the picker view item text 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 Picker View Controls
Selecting Picker View Items
wItem Property (iOS Picker View Controls)

Highlight search results