【问题标题】:How can I get the label for a scroll view in a Xcode 7.2 XCTestCase?如何在 Xcode 7.2 XCTestCase 中获取滚动视图的标签?
【发布时间】:2016-09-28 20:55:09
【问题描述】:

在 XCode 7.2 中,如果我可以得到 XCUIApplication().scrollViews["Foo"].otherElements.otherElements["Page Title"],那么可以说“给我这个名为“Foo”的 scrollView 的页面标题“?”

我已尝试询问accessibilityLabel 和staticTexts。

我已尝试将 XCUIApplication().scrollViews["Foo"]、XCUIApplication().scrollViews["Foo"].otherElements 等添加到我的监视列表中,但我没有看到任何有用的信息。

当我对XCUIApplication().scrollViews["Foo"].otherElements 执行po 时,我得到:

<snip>
↪︎Find: Descendants matching type Other
Output: {
      Other 0x7f904b60e910: traits: 8589934592, {{0.0, 0.0}, {768.0, 1024.0}}, label: 'PDF article'
      Other 0x7f9049efb6e0: traits: 8589934592, {{0.0, 0.0}, {768.0, 1024.0}}
    }

(本例中的页面标题为“PDF 文章”)

所以我觉得我至少应该可以使用 staticTexts 访问它。

【问题讨论】:

    标签: swift xctest xcode7.2


    【解决方案1】:

    看起来您的页面标题是一个不继承自 UILabel 的自定义视图(UILabel 后代被标记为 StaticTexts)。

    您需要在应用代码中的页面标题上设置可访问性标识符(不是标签)。

    pageTitle.accessibilityIdentifier = "Page Title"
    

    这应该使您的代码正常工作,并且是最佳实践。

    或者,如果您将搜索链更改为使用标签的值而不是 "Page Title",那也应该可以。但是,如果您打开具有不同标题的不同页面,这将不起作用。

    XCUIApplication().scrollViews["Foo"].otherElements["PDF article"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-13
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多