带时间戳的事件匹配错误:找不到匹配的元素

问题描述 投票:70回答:6

我正在尝试在Xcode中生成UItest。当我尝试刷UIview时出现错误:

Timestamped Event Matching Error: Failed to find matching element

error window

enter image description here

如果我尝试点击UIView,也会发生这种情况。

swift xcode7 xcode-ui-testing
6个回答
46
投票

您应该验证是否为要刷卡的UIView对象启用了“辅助功能”选项,例如:

enter image description here


3
投票

在Xcode 9.3中,这显然仍然是一个问题,我所做的是:

  • 退出Xcode
  • 重置模拟器的设置(硬件 - >删除所有内容和设置)
  • 退出模拟器
  • 删除当前应用的派生数据
  • 重启Xcode
  • 再试一次录音 - 这次对我有用。

3
投票

通常,当想要记录的元素的父元素设置为isAccessibilityElement = true时,会出现此问题。通常,您必须将父元素设置为false才能访问子元素。例如:如果视图中有UILabel,则视图的可访问性应设置为false,UILabel的可访问性设置为true。


2
投票

为了记录新的测试,我认为还没有解决方案。但是,如果你使用扩展强制点击与已经存在的测试,工作。

使用示例:

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 test - UI Testing Failure - Failed to scroll to visible (by AX action) when tap on Search field "Cancel' button


1
投票

我偶尔遇到这个问题。从DerivedData删除应用程序的目录似乎有所帮助。


1
投票

对我自己有用的解决方案是以不同方式识别对象。 在Xcode 8中,我能够使用以下内容:

XCUIApplication().tables.cells["Camera Roll"].buttons["Camera Roll"].tap()

使用Xcode 9,我收到了这个问题中提到的错误。结束使用以下,有效(比原始选项更加灵活)

XCUIApplication().cells.element(boundBy: 1).tap()
© www.soinside.com 2019 - 2024. All rights reserved.