【发布时间】:2020-07-03 11:45:40
【问题描述】:
我想测试一个按钮的点击行为。执行button.tap()时,测试失败。
XCTContext.runActivity(named: "Validate reply click") { (activity) in
let button = App.buttons.matching(identifier: "Reply-ok").firstMatch
button.tap()
}
错误信息: 无法合成事件:无法计算 Button 的命中点,标识符:“Reply-ok”,标签:“Reply 1: ok.”:来自 AXUIElementCopyMultipleAttributeValues 的 2062、2021、2123 的可访问性错误 kAXErrorInvalidUIElement
尝试过的解决方案:
- 将 tap 改为 forceTap
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()
}
}
- 检查按钮是否存在或可点击
XCTContext.runActivity(named: "Validate reply click") { (activity) in
let button = App.buttons.matching(identifier: "Reply-ok").firstMatch
if button.exists, button.isHittable {
button.tap()
}
}
这两种解决方案都不起作用,我仍然遇到同样的错误。知道为什么会出现错误以及如何解决这个问题吗?
【问题讨论】: