这是我的简单 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/