8

I would like to be able to tap a concrete button on my stack of views. To achieve this, first I set on my code an accessibility id:

Button(action: {
                 withAnimation(.easeOut(duration: 1)) {
                    self.modalShown.toggle()
                 }

                }) {
                      FilterButton()
                     .accessibility(identifier: "modalFilterViewBtn")
                    }
                    .buttonStyle(PlainButtonStyle())
                }

So, then on my text case I tried to look for that id:

IOSElement elem1 = driver.findElementByAccessibilityId("modalFilterViewBtn");
    wait.until(ExpectedConditions.elementToBeClickable(elem1));
    elem1.click();

And I obtain as a result: An element could not be located on the page using the given search parameters.(..)

Finally if I use the Appium inspector to know the accessibility id of my desired element, it seems to be another name that is not the same that I had set in code:

enter image description here

Even if I look for the element with that id("Filter"), it also can not be found during my test case.

So, what is the correct way to set this accessibility id using SwiftUI?

Thank you

Andoni Da Silva
  • 1,161
  • 15
  • 31

1 Answers1

17

I assume it should be like

Button(action: {
    // action here
}) {
    // button label view here
}
.buttonStyle(PlainButtonStyle())
.accessibility(identifier: "modalFilterViewBtn")

Note in iOS 14+ there is .accessibilityIdentifier(_ identifier: String) instead. accessibility(identifier: String) is deprecated.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Asperi
  • 228,894
  • 20
  • 464
  • 690