ios - 如何在 XCUIElementQuery 中获取 XCUIElement 的索引?

标签 ios xcode swift xcode-ui-testing ui-testing

这是我的简单 UITest (自定义 tabbarcontroller 中的选项卡顺序):

func testIsOrderOfTabsSaved() {

    let app = XCUIApplication()
    let tabBarsQuery = app.tabBars
    tabBarsQuery.buttons["More"].tap()
    app.navigationBars["More"].buttons["Edit"].tap()
    tabBarsQuery.buttons["Takeaway"].swipeLeft()
    tabBarsQuery.buttons["In Restaurant"].swipeLeft()

    //here, how to get position of moved button with text "In Restaurant"?

注意:

可以通过索引从XCUIElementQuery 获取XCUIElement。我可以用另一种方式来做吗?

最佳答案

似乎查询会根据屏幕上的位置自动按顺序返回。

for i in 0...tabsQuery.buttons.count {
    let ele = tabsQuery.buttons.elementBoundByIndex(i)
}

其中索引 i 表示按钮在选项卡栏中的位置,0 是最左边的选项卡,i == tabsQuery.buttons.count 是最右边的。

关于ios - 如何在 XCUIElementQuery 中获取 XCUIElement 的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32164956/

相关文章:

ios - 为什么我的动态物理体能够插入我的静态物理体?在 swift

ios - 解析和核心数据关系和指针

ios - 在构建时覆盖 NSUserDefault 首选项

swift - 如何在 SwiftUI 列表中获取行索引?

swift - 为数组中的项目赋值给出条件绑定(bind)中的绑定(bind)值必须是可选类型

ios - swift - 将字符串转换为日期,然后转换为不同格式的字符串

ios - Swift:检查数据类型是否可以转换为 Double

ios - 重新启动动画 ios swift

ios - 是否可以在 nib 中使用 View Controller ?还是只是 UIViews?

ios - 执行 iOS 应用程序的硬关闭并在带有自动化的模拟器中以保存的状态重新打开