1

I've hit a roadblock in trying to write some automated tests for my iPhone app. Judging from the documentation I feel like this should select the first row of the first component of my UIPickerView:

var picker = UIATarget.localTarget().frontMostApp().mainWindow().pickers()[0];
var aWheel = picker.wheels()[0];
var someVals = aWheel.values();

aWheel.selectValue(someVals[0]);

But instead I get the following error, logged in Instruments:

       Exception raised while running script: - selectValue requires a valid value

Any ideas how I can

  • Set predictable values on my UIPickerView cells/components? Currently, they all use custom UIViews, not the standard labels.

or

  • Somehow get an array of values from my existing cells to iterate through?

What am I missing here?

dtuckernet
  • 7,817
  • 5
  • 39
  • 54
Chris Ladd
  • 2,795
  • 1
  • 29
  • 22

4 Answers4

3

I also had this issue.

try var newValue = someVals[0].toString();

And then use the newValue to select your value in your picker:

aWheel.selectValue(newValue);

This worked for me

2

For me the selectValue method on the picker wheel object didn't work if values in the wheel were empty, had spaces or had some special characters. I ended up having to use tapWithOptions({ tapOffset: { x: 0.23, y: 0.72 } }) instead.

user883452
  • 21
  • 2
1

Your code looks correct. You need to add some checks though. I think your picker is empty, or you dont have a valid handler to it. Here is how I do it my code. Hope it helps.

target      = UIATarget.localTarget();
app         = target.frontMostApp();
mainWindow  = app.mainWindow();


function selectOffice() {

    UIALogger.logStart("selectOffice");

    var validField = false;

    try {

        var picker = mainWindow.pickers()[0];

        if (picker.isValid()) {

            var wheel = picker.wheels()[0];

            if (wheel.isValid()){

                var pickedItems = wheel.values();
                var nrOfItems = pickedItems.length;

                if (nrOfItems > 0 ) {
                    wheel.selectValue(pickedItems[nrOfItems-1]);
                    validField = true;
                }
            }
        }
    }
    catch(error) {
        UIALogger.logFail(error);
    }

    if (validField == true ) {
        UIALogger.logPass("selectOffice");
    } else {
        UIALogger.logFail("Couldnt find a valid control");
    }
    target.delay(1);
}
Konrad77
  • 2,515
  • 1
  • 19
  • 36
0

SelectValue() does not seem to work for text-values. It works for numeric, though.

For text-values, I just get the current value and tap until I find it.

SchmitzIT
  • 9,227
  • 9
  • 65
  • 92