1

I have a UICollectionViewCell subclass, built in interface builder. In my test I want to tap on the first one.

The code:

- (void)tapFirstThing
{
    SLElement *firstCell = [SLElement elementWithAccessibilityLabel:@"First"];
    [firstCell logElement];
    [firstCell tap];
}

From the inspector log:

<MYCollectionViewCell: 0x1381bc60; frame = (0 210; 320 560); id = 'First'; label = 'First'; accessibilityElement = YES>
Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().elements()["UIWindow: 0xc8652d0"].elements()["UICollectionView: 0xd8eda00"].elements()["UICollectionViewCellAccessibilityElement: 0xcf15120"]

Things I did at cell creation time in desperation that seemed to basically have no effect other than me wasting a few hours today:

if (indexPath.row == 0) {
    cell.isAccessibilityElement = YES;
    cell.accessibilityLabel = @"First";
    cell.accessibilityIdentifier = @"First";
    cell.accessibilityActivationPoint = CGPointMake(CGRectGetWidth(cell.bounds) / 2.0, CGRectGetHeight(cell.bounds) / 2.0);
}

So... how am I supposed to do this? What does that error even mean? I don't understand how I can log it, but it's UIAElementNil?

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
  • Hi @jeffamaphone, I'm Subliminal's maintainer--sorry for the delay in replying. In local testing, I'm able to tap on a collection view using code similar to yours--just setting `isAccessibilityElement = YES` and `accessibilityLabel = @"First"` makes it matchable for me. Could you put up your view controller and cell class on GitHub, by any chance? – Jeffrey Wear Jun 11 '14 at 01:53
  • What you see in the logs is a bit of a mismatch between Subliminal and (behind the scenes) UIAutomation. `-logElement` prints the actual element you're trying to match--the cell--but inside collection views, UIAutomation works with "mock cells" instead. The error means that UIAutomation can't find the corresponding mock cell for some reason. – Jeffrey Wear Jun 11 '14 at 01:56
  • I have also found issues where a ```UITableViewCell``` is untappable. Despite the cell being valid and logging fine, I'll get an ```Element '' is not tappable.``` error when calling ```elementWithAccessibilityLabel``` or ```elementWithAccessibilityIdentifier```. What I have found is that explicitly setting ***both*** the ```accessibilityIdentifier``` and ```accessibilityLabel``` for the cell somehow makes either work. – Praveen Jul 02 '14 at 10:26
  • Yeah, my problem is I can't generate a minimum repro case in the Subliminal integration tests to demonstrate the issue. It's something in our code that is subtle and complex that makes this hard. – i_am_jorf Jul 02 '14 at 15:27

0 Answers0