我想测试按钮的点击行为。执行button.tap()时,测试失败。
XCTContext.runActivity(named: "Validate reply click") { (activity) in
let button = App.buttons.matching(identifier: "Reply-ok").firstMatch
button.tap()
}
Run Code Online (Sandbox Code Playgroud)
错误消息:无法合成事件:无法计算按钮的命中点,标识符:“Reply-ok”,标签:“Reply 1:ok。”:来自 AXUIElementCopyMultipleAttributeValues 的 2062、2021、2123 的辅助功能错误 kAXErrorInvalidUIElement
尝试过的解决方案:
func forceTapElement(element: XCUIElement) {
msleep(milliSeconds: 1000)
if self.isHittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0)).withOffset(CGVector(dx: element.frame.origin.x, dy: element.frame.origin.y))
coordinate.tap()
}
}
Run Code Online (Sandbox Code Playgroud)
XCTContext.runActivity(named: "Validate reply click") { (activity) in
let button = App.buttons.matching(identifier: "Reply-ok").firstMatch
if button.exists, button.isHittable {
button.tap()
}
}
Run Code Online (Sandbox Code Playgroud)
这两种解决方案都不起作用,我仍然遇到同样的错误。知道为什么会出现错误以及如何解决这个问题吗?
您的问题forceTapElement是,在某些情况下,您会在第四行中收到错误,因为isHittable可能会失败。
尝试使用这个扩展
extension XCUIElement {
func tapUnhittable() {
XCTContext.runActivity(named: "Tap \(self) by coordinate") { _ in
coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1987 次 |
| 最近记录: |