5

I have created a simple project using storyboards containing just a UIDatePicker with mode=Date (so that dates appear like "November" "28" "2011").

Within Instruments UI Automation I am trying to set the values of the individual date picker wheels.

I can successfully use the selectValue() method to set the wheels which contains numeric values but cannot manage to set text value of the month e.g. "November".

This works..

target.frontMostApp().mainWindow().pickers()[0].wheels()[1].selectValue(12);

but this doesn't..

target.frontMostApp().mainWindow().pickers()[0].wheels()[0].selectValue("November");

I get the error: Script threw an uncaught JavaScript error: - selectValue is not supported on a picker with undefined values

I have done a UIATarget.localTarget().frontMostApp().logElementTree() and can see the value is correct:

UIAPickerWheel: value:November rect:{{1, 142}, {146, 216}}

Please can anyone advise on what I might be doing wrong, many thanks.

MandyW
  • 1,117
  • 3
  • 14
  • 23

5 Answers5

4

This has been remedied in the latest version of xcode (4.5.2)

target.frontMostApp().mainWindow().pickers()[0].wheels()[0].selectValue("November");

It will now work.

Alec
  • 8,529
  • 8
  • 37
  • 63
Neil Horton
  • 707
  • 6
  • 13
2
while(monthWheel.value() != "June"){
  monthWheel.tapWithOptions({tapOffset:{x:0.5, y:0.33}});
  target.delay(0.5);
}

value is not variable, it is a function so you should call value() on month wheel like I used. and tapWithOptions() will take you to next row in the wheel.

bool.dev
  • 17,508
  • 5
  • 69
  • 93
Keshav
  • 2,965
  • 3
  • 25
  • 30
0

Just find all the values of the particular picker wheel using

var pickerWheel1Values  = picker.wheels()[1]. values();

and if you want to set November just do

picker.wheels()[index]. selectValue (pickerWheel1Values[10]);
FelixSFD
  • 6,052
  • 10
  • 43
  • 117
raja pateriya
  • 332
  • 2
  • 15
0

For anyone using Appium see this page here on the discussion board: https://groups.google.com/d/msg/appium-discuss/uYdRTdQDvpU/2I7KSFHnqFwJ

The flow goes like this:

  • get your picker element (tag name: picker)
  • get all the wheels for that picker (tag name: pickerwheel)
  • you can list values for that wheel by doing element.getAttribute("values")
  • you can set the value by doing element.setValue(myNewValue)

The last step is wrong and you need to use sendKeys() instead of setValue()

For a real example like how I used it would be something like this

String pickerWheelLocation = "UIATarget.localTarget().frontMostApp().windows()[3].pickers()[0].elements()[0]"
By pickerWheelBy = MobileBy.IosUIAutomation(pickerWheelLocation)
IOSElement pickerWheel = WebDriverHelper.getDriver().findElement(pickerWheelBy);
pickerWheel.sendKeys("New Value");

IOSElement doneButton = WebDriverHelper.getDriver().findElement(MobileBy.IosUIAutomation("UIATarget.localTarget().frontMostApp().windows()[2].toolbars()[0].buttons()["Done"]"));
    doneButton.click();
plosco
  • 891
  • 1
  • 10
  • 18
0

I would tap until my value is the one I want. Since the value set is 12 months, it'll roll around.

while(target.frontMostApp().mainWindow().pickers()[0].wheels()[0].value != "November"){
  target.frontMostApp().mainWindow().pickers()[0].wheels()[0].tap();
}
animuson
  • 53,861
  • 28
  • 137
  • 147
  • Hi good idea but this doesn't work - when I try this I just get stuck in an infinite loop and the wheel doesn't roll on :-( – MandyW Dec 16 '11 at 17:57
  • while(monthWheel.value != "June"){ monthWheel.tapWithOptions({tapOffset:{x:0.5, y:0.33}}); monthWheel.logElementTree(); target.delay(0.5); } though monthWheel.value is still not returning a valid result – FishStix Feb 01 '12 at 02:14