iOS UI Testing tap on first index of the table

情到浓时终转凉″ 提交于 2019-12-05 08:19:46

Use -elementBoundByIndex on your app's cells.

XCUIApplication *app = [[XCUIApplication alloc] init];
[[app.cells elementBoundByIndex: 0] tap];

Swift 4

@Joe Masilotti's solution didn't work for me. So I used:

let app = XCUIApplication()
app.tables["table's accessibilityIdentifier"].cells.allElementsBoundByIndex.first?.tap()

"table's accessibilityIdentifier" should be replaced by your table's accessibilityIdentifier.

Possibly this will save a few minutes for someone.

Swift

If you're doing UI Testing, this will be helpful:

let cellCount = app.tables.cells.count
XCTAssertTrue(cellCount > 0)

let firstCell = app.tables.cells.element(boundBy: 0)
XCTAssertTrue(firstCell.exists)
firstCell.tap()

To answer your question though, you only need these 2 lines:

let firstCell = app.tables.cells.element(boundBy: 0)
firstCell.tap()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!