【发布时间】:2019-06-17 18:43:24
【问题描述】:
我正在测试 XCUItest 中的单元格内容的表格视图。就我而言,我不知道单元格文本的顺序,也不允许我为文本设置可访问性 ID。给定内部文本,如何获取单元格的索引?
例如,如果我想获取包含文本“Cell 2 Text”的单元格的索引,我会尝试这样的操作:
func testSample() {
let app = XCUIApplication()
let table = app.tables
let cells = table.cells
let indexOfCell2Text = cells.containing(.staticText, identifier: "Cell 2 Text").element.index(ofAccessibilityElement: "I dunno")
print(indexOfCell2Text)
}
我觉得我很接近,但我不确定。任何人都可以提出解决方案吗?
如果之前有人问过这个问题,我深表歉意。我找不到任何关于此的具体内容。
我之前访问过的参考资料: https://developer.apple.com/documentation/xctest/xcuielementquery/1500842-element
How can I verify existence of text inside a table view row given its index in an XCTest UI Test?
【问题讨论】:
标签: swift xcode xctest xcuitest