BigCheesy
BigCheesy

Reputation: 1138

I'm having issues getting a button by label

I'm having an issue just getting a UIButton by accessibility label.

Here's how I'm setting the accessibility of the UIButton:

[_dobblerButton setAccessibilityLabel:@"dobbler_button"];
[_dobblerButton setAccessibilityTraits:UIAccessibilityTraitButton];
[_dobblerButton setIsAccessibilityElement:YES];

Here's how I'm trying to get it:

_usernameField = [SLButton elementWithAccessibilityLabel:@"dobbler_button"];
[_usernameField logElement];

The log call throws an error:

Unknown location: Unexpected exception occurred SLUIAElementInvalidException for reason: Element '<SLButton description:"dobbler_button">' does not exist.

I've tried using SLButton elementMatching to print out all accessibility labels, and dobbler_button definitely shows up.

Let me know if there's anything else I can provide to help debug this.

Upvotes: 0

Views: 84

Answers (2)

BigCheesy
BigCheesy

Reputation: 1138

It turns out I had accessibility turned on by the button's containing view. This doesn't work, per Apple's docs

if your application displays a custom view that contains other elements with which users interact, you need to make the contained elements separately accessible. At the same time, you need to make sure that the container view itself is not accessible. The reason is that users interact with the contents of the container, not with the container itself.

Upvotes: 2

MoralCode
MoralCode

Reputation: 2050

I think you can achieve this by going to your .storyboard file (or wherever you design the UI) click the button and it should be in one of the menus on the right.

Upvotes: 0

Related Questions