Are using accessibility ids to find elements good practice?

Hi, I’m brand new to Appium but one thing that has confused me is the use of accessibility ids for finding elements, I thought the purpose of these was to provide partial sighted users with content descriptions for text to speech, they should therefore be localised and thus useless for identifying elements. I guess that the majority of developers probably don’t put these in. ( I didn’t even realise they existed until now) so its not a big deal, but maybe the documentation should state that really this is a bit of a misuse of a OS feature and you cannot use them for identification and making a more accessible app at the same time. If a user has text to speech enabled will they not get these labels read out to them? Or am I completely missing something.

Thank you

Martin…

hi,

https://developer.apple.com/documentation/appkit/nsaccessibility/1535023-accessibilityidentifier ->
This property holds the unique ID for the accessibility element. It is often used in automated testing. :slight_smile:

It may be worth documenting (we take pull requests for documentation http://appium.io/docs/en/commands/element/find-elements/#selector-strategies).

I would argue that the two use-cases (visually impaired users and Appium element locators) don’t have to contradict each other. You can have content descriptions that help the visually impaired and also be used by Appium to locate elements.

The way I think of it is that Appium is a black-box, automated UI testing tool that is meant to simulate a person using your app. So it kind of makes sense that Appium would locate elements the same way a visually impaired person locates elements.

You are correct though that you it’s bad practice to be adding unneeded content descriptions that are used solely for element location. This issue echoes your concerns: https://github.com/appium/appium/issues/6025

Thanks so much for the quick reply, It seems like Apple have already worked around the problem by adding a seperate identifier for automated testing https://developer.apple.com/documentation/uikit/uiaccessibilityidentification/1623132-accessibilityidentifier. However I don’t think there is an Android equivalent. Our app has a lot of non-english speaking users so Im not sure I should be adding content descriptions for test purposes.

Maybe we all need to start thinking of Appium as a visually impaired user. Then the use case of “content‑description” can still have a single purpose. That said, iOS definitely has both accessiblityIdentifier as well as accessibilityLabel. The Label is for screen readers, the Identifier is for Appium.