swift – 带时间戳的事件匹配错误:找不到匹配的元素
swift – 带时间戳的事件匹配错误:找不到匹配的元素
问题:
我正在尝试在Xcode中生成UItest。 当我尝试刷UIview时出现错误:
Timestamped Event Matching Error: Failed to find matching element
如果我尝试点击UIView,也会发生这种情况。
I’m trying to generate a UItest in Xcode.When I try to swipe UIview I get an error:error windowThis also happens if I try to tap UIView.
解决方案:
方案1:
您应该验证是否为要刷卡的UIView对象启用了“辅助功能”选项,例如:
方案2:
通常,当想要记录的元素的父元素设置为isAccessibilityElement = true时,会出现此问题。 通常,您必须将父元素设置为false才能访问子元素。 例如:如果视图中有UILabel,则视图的可访问性应设置为false,UILabel的可访问性设置为true。
方案3:
在Xcode 9.3中,这显然仍然是一个问题,我所做的是:
- 退出Xcode
- 重置模拟器的设置(硬件 – >删除所有内容和设置)
- 退出模拟器
- 删除当前应用的派生数据
- 重启Xcode
- 再试一次录音 – 这次对我有用。
方案4:
为了记录新的测试,我认为还没有解决方案。 但是,如果你使用扩展强制点击与已经存在的测试,工作。
使用示例:
extension XCUIElement {
func forceTapElement() {
if self.hittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))
coordinate.tap()
}
}
}
func testSomethingWithCells() {
let app = XCUIApplication()
let cells = app.tables.cells
sleep(1)
cells.elementBoundByIndex(0).forceTapElement()
}
你可以在这里查看原帖:
Xcode UI测试 – UI测试失败 – 点击搜索字段“取消”按钮时无法滚动到可见(通过AX操作)
方案5:
我偶尔遇到这个问题。 从DerivedData删除应用程序的目录似乎有所帮助。
方案6:
对我自己有用的解决方案是以不同方式识别对象。
在Xcode 8中,我能够使用以下内容:
XCUIApplication().tables.cells["Camera Roll"].buttons["Camera Roll"].tap()
使用Xcode 9,我收到了这个问题中提到的错误。 结束使用以下,有效(比原始选项更加灵活)
XCUIApplication().cells.element(boundBy: 1).tap()