有没有办法在iOS UI测试自动化中使用坐标选择元素?

时间:2016-04-28 16:06:18

标签: ios swift ui-automation ios-ui-automation

我正在处理有许多元素的UICollectionView。其中之一,它是一个UISuplementaryView,包含许多可点击的单元格(它是一个日历)。

当我po print(debugDescription)时,我得到许多类似“其他”的元素,如下所示 Other 0x7f8a4cb06e30: traits: 8589934592, {{0.0, -1175.5}, {50.0, 38.0}}
有谁知道是否有办法使用这些坐标与元素进行交互?

1 个答案:

答案 0 :(得分:1)

首先尝试在下拉到坐标API之前分配元素可访问性特征。在 production 代码中,在accessibilityIdentifier上设置UISupplementaryView

func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
    UICollectionReusableView *reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Identifier" forIndexPath:indexPath];
    reusableView.accessibilityIdentifier = "Reusable View \(indexPath.row)"
    return reusableView
}

然后,在UI测试中,通过以下方式与其进行交互:

let app = XCUIApplication()
app.otherElements["Reusable View 3"].tap()