I have a VStack, which loops through and prints a view, based on the number of objects within the array. Each view has a unique accessibility identifier person_x
, dependant on the ID of the person.
VStack() {
ForEach(model.people) { person in
personView(model: person)
.accessibilityElement(children: .contain)
.accessibilityIdentifier("person_\(person.id)")
}
Within the personView
there's additional elements which also have accessibility identifiers, but these are not "unique", they're generically named, for example:
private var carStack: some View {
CarSwiftUIView(viewModel: viewModel.carViewModel)
.accessibilityIdentifier("car")
}
So the hierarchy of the accessibility elements would be like this:
- person_1
- car
- person_2
- car
- person_3
- car
- person_4
- car etc..
How can I interact with a car
element, within a specific person
view.
The closest I got, but still without success, was:
let elements = app.descendants(matching: .any)["person_1"]
Any help would be hugely appreciated. Thank you.