xcode 时间戳事件匹配错误:未能找到匹配元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36616891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Timestamped Event Matching Error: Failed to find matching element
提问by shay
I'm trying to generate a UItest in Xcode. When I try to swipe UIview I get an error:
我正在尝试在 Xcode 中生成一个 UItest。当我尝试滑动 UIview 时出现错误:
Timestamped Event Matching Error: Failed to find matching element
This also happens if I try to tap UIView.
如果我尝试点击 UIView,也会发生这种情况。
回答by AmitW
回答by Souma Paul
Usually this issue is observed when the parent element of the element yo want to record is set to isAccessibilityElement=true. In general, you have to have the parent element set to false to access the child element. For example: if you have a UILabel inside a view, the accessibility should be set to false for the view and set to true for the UILabel.
通常,当您要记录的元素的父元素设置为 isAccessibilityElement=true 时,会观察到此问题。通常,您必须将父元素设置为 false 才能访问子元素。例如:如果视图中有 UILabel,则视图的可访问性应设置为 false,而 UILabel 的可访问性应设置为 true。
回答by commanda
In Xcode 9.3, where this is apparently still a problem, what I did was:
在 Xcode 9.3 中,这显然仍然是一个问题,我所做的是:
- Quit Xcode
- Reset the Simulator's settings (Hardware -> Erase all contents and settings)
- Quit the Simulator
- Delete the derived data for the current app
- Restart Xcode
- Try recording again - it worked this time for me.
- 退出 Xcode
- 重置模拟器的设置(硬件 -> 擦除所有内容和设置)
- 退出模拟器
- 删除当前应用的派生数据
- 重启Xcode
- 再次尝试录制 - 这次对我有用。
回答by Dave L
I've been occasionally running into this problem. Delete the app's directory from DerivedData seems to help.
我偶尔会遇到这个问题。从 DerivedData 中删除应用程序的目录似乎有帮助。
回答by Sophy Swicz
For recording a new test, I don't think there's a solution yet. But, if you use an extension forcing tap with a test that already exists, works.
对于录制新测试,我认为目前还没有解决方案。但是,如果您将扩展强制点击与已存在的测试一起使用,则有效。
Example of use:
使用示例:
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()
}
You can check the original post here:
您可以在此处查看原始帖子:
回答by Charlie Seligman
A solution that worked for myself was to identify the object differently.
In Xcode 8 I was able to use the following:
一个对我有用的解决方案是以不同的方式识别对象。
在 Xcode 8 中,我能够使用以下内容:
XCUIApplication().tables.cells["Camera Roll"].buttons["Camera Roll"].tap()
With Xcode 9 I got the error mentioned in this question. Ended up using the following, which worked (al beit more flakey than the original option)
使用 Xcode 9 我得到了这个问题中提到的错误。最终使用了以下方法,该方法有效(尽管比原始选项更不稳定)
XCUIApplication().cells.element(boundBy: 1).tap()