func tapCoordinate(at point: CGPoint) { let normalized = coordinate(withNormalizedOffset: .zero) let offset = CGVector(dx: point.x, dy: point.y) let coordinate = normalized.withOffset(offset) coordinate.tap() }
let app = XCUIApplication() app.launch() sleep(5) let point = CGPoint(x: 328.0, y: 392.0) app.tapCoordinate(at: point)
使用coordinate函数直接定位使用的是CGVector,无法直接定位到页面上的点,需要使用CGPoint才能定位
配合app.debugDescription获得的UI树使用
原文:https://www.cnblogs.com/teapotpot/p/14390926.html