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().mainWi开发者_StackOverflow中文版ndow().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?
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
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.
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);
}
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.
精彩评论