![](/img/trans.png)
[英]Why is the UI Automation instrument unable to determine if a button is enabled here?
[英]How do I determine which buttons are enabled in iOS UI Automation?
使用UI自动化工具,我知道如何测试iOS应用程序中是否启用了特定按钮:
if( btn[0].isEnabled() ) {
UIALogger.logPass("button enabled");
} else {
UIALogger.logFail("button not enabled");
}
但是,我希望能够确定界面中已启用的按钮数量,而不仅仅是确定是否已启用特定按钮。 如何确定已启用按钮的数量?
另外,如何将这些按钮的详细信息打印到控制台?
这是一个使用UIAElementArray(即app.mainWindow()。buttons())并记录已启用按钮的数量的函数:
function printEnabledButtons(list) {
var enabledButtons = 0;
for (var i=0;i<list.length;i++) {
if (list[i].isEnabled()) {
//UIALogger.logDebug("button " + list[i].name() + " is enabled");
enabledButtons++;
} else {
//UIALogger.logDebug("button " + list[i].name() + " is not enabled");
}
}
UIALogger.logDebug("number of enabled buttons: " + enabledButtons);
}
调用代码示例:
printEnabledButtons(app.mainWindow().buttons());
我已经修改了您的代码。 所以这里是:
function checkIfEnabled(list, button_name) {
var btn_enabled = false;
var list_length = list.length;
var list_item;
for (var list_index=0; list_index < list_length; list_index++) {
list_item = list[list_index];
var item_name = list_item.name();
if (list_item.isVisible () && list_item.isEnabled () &&
item_name.match(button_name.toString())){
UIALogger.logMessage ("We're IN !!! ");
btn_enabled = true;
break;
} else {
btn_enabled = false;
UIALogger.logMessage ("Still looking for a button");
}
}
return btn_enabled;
}
这是此功能的用法:
var btn_state = checkIfEnabled(app.navigationBar().buttons(),
YOUR_BTN_NAME);
然后,您可以根据需要简单地检查'btn_state'是true还是false。
芝士
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.