admin管理员组

文章数量:1314086

I'm having a very simple app, which includes a TableViewController, which displays a table with few custom cells with image, label and a button, and when you hit a button, actionSheet shows up. And so, in my custom java script (using Instruments-UIAutomation) I want to push button in my table (and I can do that without any problems), and then when actionSheet appears I just want to tap the only button (Cancel button) that it shows.

And I don't know how to do it properly. So here's my js code:

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();

And that's the message I'm getting:

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

I've also tried actionSheet().buttons()[0].tap(); - didn't help, keep getting same error.

I even tried to access actionSheet by it's accessibleLabel:

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

If it would help, that's the way I'm showing my actionSheet:

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

The elements hierarchy also seems to be correct.

Didn't find much of a helpful info on it in web... so any help would be appreciated...

I'm having a very simple app, which includes a TableViewController, which displays a table with few custom cells with image, label and a button, and when you hit a button, actionSheet shows up. And so, in my custom java script (using Instruments-UIAutomation) I want to push button in my table (and I can do that without any problems), and then when actionSheet appears I just want to tap the only button (Cancel button) that it shows.

And I don't know how to do it properly. So here's my js code:

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();

And that's the message I'm getting:

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

I've also tried actionSheet().buttons()[0].tap(); - didn't help, keep getting same error.

I even tried to access actionSheet by it's accessibleLabel:

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

If it would help, that's the way I'm showing my actionSheet:

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

The elements hierarchy also seems to be correct.

Didn't find much of a helpful info on it in web... so any help would be appreciated...

Share Improve this question edited Sep 16, 2014 at 21:19 AstroCB 12.4k20 gold badges59 silver badges74 bronze badges asked Jan 24, 2014 at 11:32 arrtemearrteme 3931 gold badge3 silver badges14 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

On iOS8, the action sheet buttons and elements just didn't seem to work so I checked in SparkInspector and it uses a collection view now:

This code will tap the bottom button that isn't the cancel button:

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

When you want to tap on actionSheet you must use as below:

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

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

But if you use window.actionSheet() it will return error.

Actually you need to use app.actionSheet() to get the actionsheet.

See UIAApplication

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

This should work

Try using this :

 //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");

本文标签: iosHow to access actionSheet (and it39s buttons) in UIAutomation with JavaScriptStack Overflow