简体   繁体   English

使用Swift在UICollectionView Cell上点击手势

[英]Tap gesture on UICollectionView Cell using Swift

I am performing UI Automation in XCode using Swift 我正在使用Swift在XCode中执行UI自动化

I would like to perform Tap gesture on UICollectionView with multiple Cells using Swift 我想使用Swift在多个单元格的UICollectionView上执行Tap手势

As my Cells keeps on updating everyday. 由于我的手机每天都在更新。 Is there anyway I can perform Tap gesture on anyone of the cell. 无论如何,我可以在任何一个单元上执行轻击手势。

Try this 尝试这个

let app = XCUIApplication()
app.tables.cells.forEach { $0.tap() }

If you want to tap on the first cell of the collectionView, assuming there is only one collection view in the current screen 如果要点击collectionView的第一个单元格,则假设当前屏幕中只有一个集合视图

let app = XCUIApplication()
app.collectionViews.element(boundBy:0).cells.element(boundBy:0).tap()

If there are multiple collectionView, find the collection View of current interest using 'po app.collectionViews.count', then find the index of the required collectionView. 如果有多个collectionView,请使用“ po app.collectionViews.count”找到当前感兴趣的collection View,然后找到所需collectionView的索引。 Say if it is at index 'n'. 说它是否在索引“ n”处。 Then 然后

let app = XCUIApplication()
app.collectionViews.element(boundBy:n).cells.element(boundBy:0).tap()

If you want to tap on any cell at random, within the collection view. 如果要在集合视图中随机点击任何单元格。 then you can try this 那你可以试试看

let app = XCUIApplication()
let randomCell = arc4random() % app.collectionViews.element(boundBy:n).cells.count
app.collectionViews.element(boundBy:n).cells.element(boundBy:randomCell).tap()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM