How to access UITabBarItem from within UITests?
Asked Answered
L

2

5

Within User Defined Runtime Attributes I set accessibilityIdentifier's value as browseTabBarButton.

But when I try to access this from UITests using:

app.tabBars.buttons["browseTabBarButton"]

UITabBarItem is not recognized. Why?

Leastways answered 2/3, 2016 at 12:23 Comment(1)
This seems to work on iOS 12, but not on iOS 10.Potsherd
S
8

If you are trying to access the UITabBarItem to switch tabs, you can achieve this in a different way by accessing the buttons within the UITabBar:

app.tabBars.firstMatch.buttons.element(boundBy: 0).tap()

School answered 15/9, 2018 at 22:26 Comment(0)
L
-1

Set accessibilityLabel instead of accessibilityIdentifier.

Leastways answered 2/3, 2016 at 12:23 Comment(3)
The accessibilityLabel is what is read out by Voice Over. It's a terrible idea setting this as an ID as the OP wants. I too would like to use the accessibilityIdentifier as I need to test in different languages so I cannot rely on the buttons label or set the accessibilityLabel to an ID.Lam
Did you get this fixed >Excogitate
Setting accessibility labels should be avoided because they can be localized.Memorize

© 2022 - 2024 — McMap. All rights reserved.