17

I have an iPhone app that I'm testing using UI Automation.

I have a button in a UITableViewCell but when I try to tap on it using UI Automation I get the following error.

Script threw an uncaught JavaScript error: target.frontMostApp().mainWindow().scrollViews()[0].elements()[element_name].tableViews()[0].elements().firstWithPredicate(name contains[c] 'Brooklyn').elements()["detailsButton"] could not be tapped

I have enabled accessibility on the button in Interface Builder and assigned the accessibility label (and identifier) "detailsButton". I can retrieve the button element and have verified that it is valid. I just can't tap it for some reason.

UIATableCell Brooklyn

The UIButton is a round rectangular button with user interaction enabled. Thanks for any feedback.

Daniel
  • 23,129
  • 12
  • 109
  • 154
kodie
  • 429
  • 6
  • 13

7 Answers7

1

You can alloc the UIButton except using round rect button. And also you can set target action of button in your controller class where table view delegate methods are presents.

Daniel
  • 23,129
  • 12
  • 109
  • 154
Wish
  • 153
  • 2
  • 14
1

Try asserting first if the button exists, use tuneup_js for easy assertions. Then assert if the button is enabled.

Have you tried: target.frontMostApp().mainWindow().scrollViews()[0].elements()[element_name].tableViews()[0].**cells()**.firstWithPredicate("name contains[c] 'Brooklyn'").elements()["detailsButton"]?

Also post another picture which shows the UIATableCell expanded where the detailsButton exists.

stackErr
  • 4,130
  • 3
  • 24
  • 48
0

You have to use ButtonType=Custom

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
Deepjyoti Roy
  • 482
  • 4
  • 15
0
but=[UIButton buttonWithType:UIButtonTypeCustom];

You must use a custom button type.

spacecash21
  • 1,331
  • 1
  • 19
  • 41
0

I don't know why you are using UI Automation. But as much I know about adding UIButton in a tableviewcell-

1) just add UIButton in UITableViewCell.
2) set UIButton's tag value and add target to that button.
3) In the target button method, you can get the UIButton object and do your stuff over there..

Hope this helps you out.

Dinesh Raja
  • 8,501
  • 5
  • 42
  • 81
Shreya
  • 198
  • 1
  • 12
0

I have met the same problem. After I added the delay it works.

UIATarget.localTarget().delay(1);
Jingjie Zhan
  • 985
  • 8
  • 12
0

You can dispatch a tap event over the entire window:

function tap_from_window(elem) {
    var mainWindow = target.frontMostApp().mainWindow();
    var elemRect = elem.rect();
    var windowRect = mainWindow.rect();

    var xPos = (20 + elemRect.origin.x) / windowRect.size.width;
    var yPos  = (50 + elemRect.origin.y) / windowRect.size.height;

    mainWindow.tapWithOptions({tapOffset:{x:xPos, y:yPos}});    
}

var target = UIATarget.localTarget();
var window = target.frontMostApp().mainWindow();
var tableView = window.scrollViews()[0].elements()[element_name].tableViews()[0];
tap_from_window(tableView.elements().firstWithPredicate(name contains[c] 'Brooklyn'))

Like many things related to iOS, I have no idea why the element cannot be tapped directly. I adapted the above function from the code in this post: scrollToVisible error while testing on a device, UIAutomation

Gardner Bickford
  • 1,934
  • 1
  • 17
  • 25