2010-09-14 55 views
1

我想在iPhone模拟器和最新的iOS SDK 4.1中使用仪器中的UIAutomation。这是有问题的JavaScript片段:iPhone UIAutomation按钮不点火

// 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显示出来并显示出来,当我记录所有按钮的名称,所以它是在界面生成器中正确配置,但出于某种原因,它不会被轻敲。我在脚本的前面有其他按钮可以轻松点击,如果我在非轻击按钮处中止脚本,我可以单击模拟器中的按钮并按预期工作。

编辑:在上面显示的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}}] 

回答

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();显示该按钮在那里。

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

然后我添加了:target.delay(1);之后,我检查该按钮是否在actionSheet上并在点击它之前。 它对我来说很有帮助,现在剧本更加稳健和稳定。

+0

我试图推动按钮以确保它仍然存在,我在按钮水龙头前至少延迟了1秒,并且我仍然没有在主窗口按钮上点击。我在按钮上做了一个logElement,它与上面的描述相同,并且OK工具栏按钮点击效果很好。你在actionSheetIsValid,actionSheetButton和tapActionSheetButtonByName函数中做了什么?谢谢。 BP – 2011-02-23 21:14:04