2010-09-14 54 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