UI Automation Testing: How do I select UIAPickerWheel values?

柔情痞子 提交于 2019-12-04 19:32:57

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);
}
bao chau

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!