gpt4 book ai didi

ios - 在 XCUITest 中,用于查找 TableView 单元格和节标题显示顺序的语法

转载 作者:行者123 更新时间:2023-11-30 11:00:03 31 4
gpt4 key购买 nike

在 XCUITest 中查询元素时,它通常按照显示的顺序返回元素。

例如:XCUIApplication().tables.cells.allElementBoundByIndex ,将返回 [XCUIElement] 的数组按照它在 UI 中显示的顺序。

无法按显示顺序一起获取节标题和单元格。

最佳答案

要查找每个部分之间显示的单元格列表,我必须使用框架。

XCUIElement().frame.origin.y

我试图确认节标题和标题中显示的元素的顺序。无法在 XCUITest 中找到语法来按显示顺序同时获取节标题和 TableView 单元格。这是因为 TableView 单元格是使用 XCUIApplication().tables.cells 标识的,节标题是使用 XCUIApplication().tables.otherElements 标识的。

步骤:1,

我向部分标题单元格和标题之间显示的单元格添加了单独的辅助功能标识符。

步骤:2,

分别获取普通表格单元格列表和其他元素单元格列表。

let elementIDMatchingPredicate = NSPredicate(format: "identifier == %@","kPodcastCellID")
let podcastCellsList: [XCUIElement] = XCUIApplication().tables.cells.matching(elementIDMatchingPredicate).allElementsBoundByIndex



let elementIDMatchingPredicate = NSPredicate(format: "identifier == %@","kPodcastSectionHeaderCellID")
let podcastCellsHeaderList: [XCUIElement] = XCUIApplication().tables.otherElements.matching(elementIDMatchingPredicate).allElementsBoundByIndex

注意:有时表格中的其他元素可能会重复,最好为单元格中显示的元素添加标识符并获取它。

步骤:3,

循环遍历列表并将其附加到二维数组中,以便您可以在每行的第一列和最后一列中添加节页眉或页脚。将元素添加到一维可能会使识别两个节标题之间的元素变得困难。

for hIndex in 0...(podcastCellsHeaderList.count - 1) {
//get the ycoordinates of header at hIndex and (hIndex+1)
//If its last header, y coordinates should be last of element.frame.origin.y + 1(not podcast header)
for cIndex in 0...(podcastCellsList.count - 1) {

//get the cells which has yCoordinates >= hIndex and lesser than hIndex+1
}
}

关于ios - 在 XCUITest 中,用于查找 TableView 单元格和节标题显示顺序的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53487615/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com