swiftxcuitestxcuielement

How to retrieve a button based off an accessibility identifier and a label


This is the error that's shown, when trying to retrieve an element that has the accessibility identifier car, and a label add:

children comes from:

let children = elements.descendants(matching: .any)["home"]

No matches found for Descendants matching type Button from input {(
    Button, identifier: 'car', label: 'add',
    Button, identifier: 'car', label: 'minus-grey', Disabled
)}}

I've attempted the use of predicates:

let predicate = NSPredicate(format: "label == %@", "add")

And trying to filter by label:

children.buttons["add"]

How can I interact with this button please?


Solution

  • children.firstMatch.tap() resolved the issue.