Unable to get UIAutomation iOS UILabel value
Asked Answered
K

2

7

I am trying to get the value "HELLO" of the UILabel shown in the iPad simulator. I have enabled accessibility and have set the label as "Label Access". But when I call target.logElementTree(), both the name and value are set to "LabelAccess" and as far as the apple docs say, the value field should contain the string that is set (in this case "Hello"). Does anybody know a fix for this?

PS: I am using the latest iOS SDK and Xcode. Apple Stack Exchange

Output of target.logElementTree();

iPad screen

Accessibility Label

Keene answered 4/5, 2012 at 14:44 Comment(4)
I think you might have more luck on apple.stackexchange.comFrosted
apple.stackexchange.com/questions/50468/…Keene
@scubaFLY Ask Different does not allow programming questions, which this unquestionably is. Stack Overflow is the right place for this question.Graphitize
Have a look at the FAQ for both this site and Ask Different and let us know if the scope of either is not clear. From where I sit, it's crystal clear - but we need things to be understandable to everyone and if you have suggestions that would help you - let us know. One thing that is certainly frowned upon is asking the same question twice - better to ask once and flag / chat to determine where it should land rather than asking duplicates in hopes one will land like a shotgun pellet hitting several sites in hopes if sticking at one.Benevolence
C
7

I think you encountered a UIAutomation bug that exists since forever.

Easiest way to get around this bug is to set the accessibilityValue to your text in code.

Something like this.

NSString *valueString = [NSString stringWithFormat:@"%d", value];
self.label.text = valueString;
self.label.accessibilityValue = valueString;

Helps those people that use Voice Over too ;-)

Cyclo answered 3/10, 2012 at 18:22 Comment(1)
Brilliant! Thank you.Playwright
N
0

thanks for the workaround. Doesn't look like this bug has been fixed. Came across this while writing Appium test for the iOS app. The element found by the driver somehow only contains accessibilityLabel and accessibilityIdentifier but not the actual text that's shown on the screen.

<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value=<accessibilityLabel> name=<accessibilityIdentifier> label=<accessibilityLabel> .../>

Has someone found if this issue has been logged with apple?

EDIT: Refer to this answer and the comment underneath. https://mcmap.net/q/1623363/-uiautomation-ios-uilabel-value

Basically need to use [accessibilityValue]: https://developer.apple.com/documentation/uikit/uiaccessibilityelement/1619583-accessibilityvalue for accessible components for the display text to show up as XCUIElementTypeStaticText.value in the page source.

For eg:

someUILabel.accessibiityLabel = "This is used for voice-over"
someUILabel.accessibilityValue = "This is displayed text"
Nessa answered 27/7, 2022 at 2:22 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.