【问题标题】:How to access UITabBarItem from within UITests?如何从 UITests 中访问 UITabBarItem?
【发布时间】:2016-03-02 12:23:02
【问题描述】:

用户定义的运行时属性中,我将accessibilityIdentifier 的值设置为browseTabBarButton

但是当我尝试从UITests 访问时,使用:

app.tabBars.buttons["browseTabBarButton"]

UITabBarItem 无法识别。为什么?

【问题讨论】:

  • 你解决过这个问题吗?
  • 这似乎适用于 iOS 12,但不适用于 iOS 10。

标签: ios xcode swift xcode-ui-testing


【解决方案1】:

如果您尝试访问UITabBarItem 以切换选项卡,您可以通过访问UITabBar 中的按钮以不同的方式实现此目的:

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

【讨论】:

  • 不错的一个。谢谢!
【解决方案2】:

设置accessibilityLabel 而不是accessibilityIdentifier

【讨论】:

  • accessibilityLabel 是 Voice Over 读出的内容。将其设置为 OP 想要的 ID 是一个糟糕的主意。我也想使用accessibilityIdentifier,因为我需要用不同的语言进行测试,所以我不能依赖按钮标签或将accessibilityLabel 设置为ID。
  • 你解决了吗>
  • 应避免设置可访问性标签,因为它们可以本地化。
猜你喜欢
  • 2020-04-03
  • 2018-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-06
  • 1970-01-01
  • 2016-11-30
  • 1970-01-01
相关资源
最近更新 更多