【问题标题】:Access last element in XCUIElement访问 XCUIElement 中的最后一个元素
【发布时间】:2019-12-04 16:12:03
【问题描述】:

在我的 UI 测试中,我有这个 XCUIElement

XCUIApplication().staticTexts["SUBMIT ORDER"]

当我打印 debugDescription 时:

po print(XCUIApplication().staticTexts["SUBMIT ORDER"].debugDescription)

有两个元素匹配:

Find: Elements matching predicate '"SUBMIT ORDER" IN identifiers'
      Output: {
        StaticText, {{0.0, 623.0}, {375.0, 44.0}}, label: 'SUBMIT ORDER'
        StaticText, {{0.0, 623.0}, {375.0, 44.0}}, label: 'SUBMIT ORDER'
      }

我的问题是:我怎样才能只在最后一个元素上创建.tap()

【问题讨论】:

    标签: swift xcode coded-ui-tests xcuitest


    【解决方案1】:

    您可以使用:

    XCUIApplication().staticTexts.matching(identifier: "SUBMIT ORDER").allElementsBoundByIndex.last
    

    【讨论】:

      【解决方案2】:

      在你的 testFunc() 中试试这个

      let app = XCUIApplication()
      
      app.staticTexts.matching(identifier: "SUBMIT ORDER").allElementsBoundByIndex.last
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-19
        • 1970-01-01
        • 1970-01-01
        • 2015-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-10
        相关资源
        最近更新 更多