2

我有一個非常簡單的應用程序,它包含一個TableViewController,它顯示一個帶有圖像,標籤和按鈕的自定義單元格的表格,當你點擊一個按鈕時,actionSheet顯示出來。所以,在我的自定義Java腳本(使用Instruments-UIAutomation)中,我想按下我的表中的按鈕(並且我可以做到這一點沒有任何問題),然後當actionSheet出現時,我只想點擊唯一的按鈕(取消按鈕)它顯示。如何使用JavaScript訪問UIAutomation中的actionSheet(以及它的按鈕)?

而且我不知道如何正確地做到這一點。因此,這裏是我的js代碼:

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

main.tableViews()[0].cells()[1].buttons()["DetailsButton"].tap(); 
target.delay(5); 
main.actionSheet().elements()[0].tap(); 

這就是我得到的消息:

Script threw an uncaught JavaScript error: 'undefined' is not a function (evaluating 'main.actionSheet()') on line 9 of New%20Script 

我也試過actionSheet().buttons()[0].tap(); - 沒有幫助,繼續得到同樣的錯誤。

我甚至嘗試通過它的accessibleLabel訪問actionSheet:

main.actionSheet()["CellNumberSheet"].elements()[0].tap(); 

如果它將幫助,這是我展示我的actionSheet方式:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow]; 

元素的層次結構似乎也正確。

enter image description here

沒有找到多少就可以了有用的信息在網絡......所以任何幫助,將不勝感激的......

回答

1

其實你需要使用app.actionSheet()來獲取行動表。

UIAApplication

app.actionSheet().elements()[0].tap(); 

這應該工作

+0

這需要我遠一點,但仍然無法正常工作......現在,當我試圖挖掘你建議的方式actionSheet的按鈕,出現其他錯誤:'無法執行對無效元素的操作:UIAElementNil from target.frontMostApp()。actionSheet()。elements()[0]'...同樣所有的方法,如checkIsValid() ','isEnabled()','isVisible()'當我將它們應用到我的actionSheet()時返回False,並且'actionSheet().name()'返回一個空字符串(而在我的文章的截圖中,看到它有一個有效的名稱「CellNumberSheet」)... – arrteme

+1

這很有趣,如何使用app.windows()[2]。元素()[1]來訪問操作表? – Sugre

+0

您建議訪問actionSheet的最後一種方式正常工作,並且所有方法(如isVisible,checkIsValid和isEnabled)都返回True。雖然仍然無法點擊actionSheet的按鈕!嘗試'app.windows()[2] .elements()[1] .elements()[0] .tap()'和'app.windows()[2] .elements()[1] .buttons() [0] .tap()'。沒有成功,它會引發錯誤「無法對無效元素執行操作」。暫時使用解決方案來輕按asctionSheet按鈕,如下所述:http://stackoverflow.com/a/5331896/3065769 – arrteme

0

嘗試使用這樣的:

//check that action sheet is on the screen 
    app.actionSheetIsValid(); 

//add some delay 
    target.delay(2); 

//check that the button is on the actionSheet 
    actionSheet.actionSheetButton("Cancel"); 

//add some delay 
    target.delay(2); 

//touch Exit button 
    actionSheet.tapActionSheetButtonByName("Cancel"); 
2

當你想敲擊actionSheet你必須如下使用:

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

target.frontMostApp().actionSheet().buttons()["Cancel"].tap(); 

但是,如果你se window.actionSheet()它會返回錯誤。

6

在iOS8上,動作片按鈕和元素只是似乎沒有工作,所以我在SparkInspector檢查,它現在使用的集合視圖:

此代碼將挖掘底部按鈕是不是取消按鈕:

target.frontMostApp().actionSheet().collectionViews()[0].visibleCells()[0].tap()

+0

這對於iPhone來說是正確的,但在iPad上我必須先訪問actionSheet:window.popover()。elements( )[0] .collectionViews()[0] .visibleCells()[「註冊新設備」]。 –

相關問題