【问题标题】:iPhone UIAutomation button tap does not fireiPhone UIAutomation 按钮点击不会触发
【发布时间】:2010-09-14 20:48:15
【问题描述】:

我正在尝试通过 iPhone 模拟器和最新的 iOS SDK 4.1 在 Instruments 中使用 UIAutomation。这是有问题的javascript的sn-p:

// there are sufficient delays here to make sure the view is loaded
UIATarget.localTarget().frontMostApp().logElementTree();
main.buttons()["theButton"].tap();
UIALogger.logMessage("The button tapped");
for (var b = 0; b < main.buttons().length; b++)
{
    UIALogger.logMessage("Button title: " + main.buttons()[b].name());
}
main.toolbar().buttons()["OK"].tap();
UIALogger.logMessage("OK tapped");

“theButton”的按钮名称显示在 logElementTree 中,并在我记录所有按钮的名称时显示,因此它在 Interface Builder 中正确配置,但由于某种原因,它没有得到轻拍。我在脚本前面有其他按钮可以正常点击,如果我在未点击的按钮处中止脚本,我可以点击模拟器中的按钮,它会按预期工作。

编辑:在上面显示的 javascript for 循环中,我让它点击 main.buttons() 数组中的每个按钮,视图上的 12 个相同按钮中只有 1 个被点击。

另外,如果您想知道,我在 javascript 文件的顶部有这段代码:

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

这是显示来自 logElementTree 放入日志消息的条目序列中的按钮信息的行:

4) UIAButton [name:theButton value:(null) NSRect: {{25, 93}, {74, 74}}]

【问题讨论】:

    标签: javascript iphone ios4 ios-ui-automation


    【解决方案1】:

    我在点击 actionSheet 上的按钮时遇到了类似的问题。我正在实际设备上执行脚本。 我的代码是:

    //check that action sheet is on the screen
        app.actionSheetIsValid();
    
    //check that the button is on the actionSheet
        actionSheet.actionSheetButton("Exit");
    
    //touch Exit button
        actionSheet.tapActionSheetButtonByName("Exit");
    

    所有功能都执行并通过,但未按下按钮。 logElementTree(); 表示按钮在那里。

    在检查按钮是否在 actionSheet 上后,我尝试添加 target.pushTimeout(5);,以便给它一些时间来检测并点击按钮。这没有帮助。

    然后我添加:target.delay(1);,在我检查按钮是否在 actionSheet 上之后以及在点击它之前。 它对我的情况有所帮助,脚本现在更加健壮和稳定。

    【讨论】:

    • 我试图轻推按钮以确保它仍然存在,我在按钮点击前至少延迟了 1 秒,但在主窗口按钮点击时仍然没有任何反应。我在按钮上做了一个 logElement,它显示的描述与上面相同,并且 OK 工具栏按钮点击效果很好。您的 actionSheetIsValid、actionSheetButton 和 tapActionSheetButtonByName 函数中发生了什么?谢谢。 BP
    猜你喜欢
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多