如何在 UI Automation iPhone 应用程序测试中处理 UIPickerView?

发布于 2024-09-26 15:44:48 字数 458 浏览 3 评论 0原文

在以下 UI 自动化脚本代码中,我能够从 UIPickerView 获取值,但无法选择选择器:

var picker = window.pickers(); 

UIALogger.logMessage("picker array count: " + picker.length);

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

UIALogger.logMessage("picker Wheel count: " + pickerWheels.length);

var pickerWheelsValues =pickerWheels[0].values();

UIALogger.logMessage("picker Values count: " + pickerWheelsValues);

pickerWheels[0].values()[0].tap();

我可能做错了什么?

In the following UI Automation script code, I'm able to get the values from a UIPickerView, but I'm not able to select the picker:

var picker = window.pickers(); 

UIALogger.logMessage("picker array count: " + picker.length);

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

UIALogger.logMessage("picker Wheel count: " + pickerWheels.length);

var pickerWheelsValues =pickerWheels[0].values();

UIALogger.logMessage("picker Values count: " + pickerWheelsValues);

pickerWheels[0].values()[0].tap();

What might I be doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

听,心雨的声音 2024-10-03 15:44:48

答案就在 Apple 开发论坛 消息 242678 中。

上你必须:

pickerWheel.tapWithOptions({x:hitPointX, y:hitPointY}, {touchCount:1, tapCount:1});

本质 hitPoint 必须位于下一行或上一行。

The answer is in the apple dev forums message 242678.

essentially you have to:

pickerWheel.tapWithOptions({x:hitPointX, y:hitPointY}, {touchCount:1, tapCount:1});

The trick is that the hitPoint has to be in the next or previous row.

在风中等你 2024-10-03 15:44:48

这是 pickerWheel 自动化的漂亮 javascript 实现
https://devforums.apple.com/message/242678

This is beautiful javascript implementation of pickerWheel automation
https://devforums.apple.com/message/242678

单调的奢华 2024-10-03 15:44:48

您应该使用 .selectValue() 方法。

var value = pickerWheels[0].values()[0]; // or any other valid value
pickerWheels[0].selectValue(value);

我发现在某些情况下 selectValue 会抛出“尝试运行脚本时发生异常”。当目标未正确设置时会发生这种情况 - 记录元素树并检查 UAITarget 名称是否不为空(如果是模拟器,则应为“iPhone Simulator”)。请参阅目标选择下的编辑活动目标,并确保在选项下设置正确的模拟器版本(您已编译)。

You should use .selectValue() method.

var value = pickerWheels[0].values()[0]; // or any other valid value
pickerWheels[0].selectValue(value);

I found that in some situations selectValue throws "An exception occurred while trying to run the script." This happens when target is not correctly set- log element tree and check if UAITarget name is not empty (in case of simulator it should be "iPhone Simulator"). See Edit Active Target under target selection and make sure that under Options correct Simulator version (you have compiled for) is set.

瑾夏年华 2024-10-03 15:44:48

适用于 XCUIAutomation(iOS 10+)

app.pickers
    .children(matching: .pickerWheel)
    .element
    .adjust(toPickerWheelValue: "My Value")

For XCUIAutomation (iOS 10+)

app.pickers
    .children(matching: .pickerWheel)
    .element
    .adjust(toPickerWheelValue: "My Value")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文