While preparing automated screenshots with Xcode UI tests for the iOS 26 release, I noticed that this simple line of code
app.buttons["myTabItem"].tap()
doesn't always work, both on iPhone and iPad Simulator. In fact, it rarely works. Even when repeating the same test, mostly it fails on that line, but a few times it works and I can see the tab item change in the simulator.
My main view looks like this:
TabView {
MyTab1()
.tag(tag1)
.tabItem {
Label("label1", systemImage: "image1")
}
MyTab2()
.tag(tag2)
.tabItem {
Label("label2", systemImage: "image2")
.accessibilityIdentifier("myTabItem")
}
The error I get is
Failed to tap "myTabItem" Button: No matches found for Elements matching predicate '"myTabItem" IN identifiers' from input
In the given list of buttons, I see the tab items with their labels, but none of them seem to have an identifier, while other buttons have the correct identifier. I wonder how this can only sometimes work.
I tried isolating the issue by iteratively commenting out parts of the SwiftUI code, but unfortunately the behaviour seems erratic. When a change results in the issue not happening anymore, undoing the last X changes often causes the issue to stay away, even with configurations that previously had the issue. I've already spent almost a whole day trying to find the root cause, but with such apparently random behaviour it has proven impossible.
Of course, I cannot reproduce the issue with a fresh test project, so the only way to reproduce it with 95% probability is running my original project.
Has anyone had the same issue, or does anyone know how I could debug this to find out what causes my UI test to not be able to tap another tab item?