2

I am currently detecting elements by their accessibility labels when writing automation testing? This causes a lot of problems.

  • Is this the correct way of detecting elements?
  • If not is there a better way to detect elements without using the accessibility label?
nschum
  • 15,322
  • 5
  • 58
  • 56
aryaxt
  • 76,198
  • 92
  • 293
  • 442

2 Answers2

4

UI Automation uses the accessibility label (if it’s set) to derive a name property for each element. Aside from the obvious benefits, using such names can greatly simplify development and maintenance of your test scripts.

The name property is one of four properties of these elements that can be very useful in your test scripts.

  • name: derived from the accessibility label
  • value: the current value of the control, for example, the text in a text field
  • elements: any child elements contained within the current element, for example, the cells in a table view
  • parent: the element that contains the current element

Instruments User Guide

Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
user726916
  • 166
  • 3
0

Don't understand what you mean by "This causes a lot of problems.". Accessing elements by their accessibility properties in Automation Instrument is quite easy.

var button = UIATarget.localTarget().frontMostApp().mainWindow().buttons()["Cancel"];

Of course you can access elements also by their order on the screen. For example:

var button = UIATarget.localTarget().frontMostApp().mainWindow().buttons()[3];

will refer to 4th button (they are numbered from 0) label on your screen. But in case you will decide to rearrange elements on your screen in next version of the app this method can broke your tests, therefore accessing them by accessibility label is more safe.

In addition accessibility elements makes your app more accessible for people (with disabilities) who will rely on VoiceOver for using app interface- so using accessibility properties in making interface tests force you to build better accessibility for your app.

jki
  • 4,617
  • 1
  • 34
  • 29