In your tests, you may need to check the state of a picker view item. For example, you may need to check if the item is selected before performing certain actions.
Getting Index of a Selected Item
The iOS PickerView object provides a special wSelectedItem property that you can use to determine which item is currently selected in the control. This property has a Wheel parameter that specifies the used wheel by its index (starting from 0). The property returns the number of the selected item.
The example below posts the selected item from the first wheel of the picker view to the test log:
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();
  // Store the selected item's index in the variable
  var selected = pickerview.wSelectedItem(0);
  // Post the selected items's text to the log
  Log.Message(selected, 0)
}
Python
def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the PickerView object 
  p = Mobile.Device().Process("SampleApp")
  pickerview = p.Window(3).PickerView()
  # Store the selected item's index in the variable
  selected = pickerview.wSelectedItem[0]
  # Post the selected items's text to the log
  Log.Message(selected, 0)
VBScript
Sub Test()
  Dim p, pickerview, selected
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the PickerView object
  Set p = Mobile.Device.Process("SampleApp")
  Set pickerview = p.Window(3).PickerView
  ' Store the selected item's index in the variable
  selected = pickerview.wSelectedItem(0)
  ' Post the selected items's text to the log
  Log.Message(pickerview.wItem(selected, 0))
End Sub
DelphiScript
procedure Test();
var
  p, pickerview, selected;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the PickerView object
  p := Mobile.Device.Process('SampleApp');
  pickerview := p.Window(3).PickerView;
  // Store the selected item's index in the variable
  selected := pickerview.wSelectedItem;
  // Post the selected items's text to the log
  Log.Message(selected, 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)["PickerView"]();
  // Store the selected item's index in the variable
  var selected = pickerview["wSelectedItem"](0);
  // Post the selected items's text to the log
  Log["Message"](selected, 0)
}
Checking Picker View Item State From Keyword Tests
To check if a picker view item is selected 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
Working With iOS Picker View Controls - Basic Concepts
wSelectedItem Property (Specific to iOS Picker View Controls)
