'XCUITest - Failed to synthesize event: Failed to compute hit point for Button
I want to test a button's click behavior. When executing button.tap(), the test fails.
XCTContext.runActivity(named: "Validate reply click") { (activity) in
let button = App.buttons.matching(identifier: "Reply-ok").firstMatch
button.tap()
}
Error message: Failed to synthesize event: Failed to compute hit point for Button, identifier: 'Reply-ok', label: 'Reply 1: ok.': Accessibility error kAXErrorInvalidUIElement from AXUIElementCopyMultipleAttributeValues for 2062, 2021, 2123
Tried solution:
- Change tap to 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()
}
}
- Check if the button exists or hittable
XCTContext.runActivity(named: "Validate reply click") { (activity) in
let button = App.buttons.matching(identifier: "Reply-ok").firstMatch
if button.exists, button.isHittable {
button.tap()
}
}
Neither solution worked, I still get the same error. Any idea why the error appears and how to resolve this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
