let app = XCUIApplication()
let studentsTable = app.tables["studentsTable"]
let detailButton = studentsTable.buttons["More Info, TestName, TestUserName, 2"]
它有效,但我很确定,还有更优雅的方法。
最佳答案
您可以通过设置可访问性标识符直接访问该按钮。在您的表格示例中,您可以在表格 View 的数据源中这样做。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(Cell.Identifier, forIndexPath: indexPath)
cell.accessoryView = UIButton() // your custom button
cell.accessoryView?.accessibilityIdentifier = "Cell \(indexPath.row + 1) Button"
return cell
}
然后您可以在 UI 测试中单独点击每个按钮。
let app = XCUIApplication()
let firstAccessoryButton = app.buttons["Cell 1 Button"]
firstAccessoryButton.tap()
关于ios - 如何通过 Xcode 中 UITests 下的标识符访问详细信息披露按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37875479/