ios - Xcode UI 测试 - 找不到刚刚记录的元素

标签 ios objective-c xcode-ui-testing ui-testing uitest

我正在尝试 Xcode UI 测试。我刚刚录制了一个简单的测试并重播了它,但第一步失败了。代码是:

XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElementQuery *scrollViewsQuery = app.scrollViews;
[[scrollViewsQuery.otherElements containingType:XCUIElementTypeStaticText identifier:@"First Page"].element tap];

失败的行是最后一行,错误消息是“UI 测试失败 - 未找到 ScrollView 的匹配项”

为什么会失败?我如何在此 View 中与此元素交互?

最佳答案

尝试直接引用静态文本,而不是通过 otherElements 访问器。

[scrollViewsQuery.staticTexts[@"First Page"] 点击];

关于ios - Xcode UI 测试 - 找不到刚刚记录的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36501559/

相关文章:

objective-c - 在 XCode 中使用 Objective C 中的 libjpeg

c - 我如何实际使用授权服务?

ios - 正确使用 Foundation_EXPORT

ios - 带有 UISegmentedControl AutoLayout 的 UIToolbar(/全宽)

ios - NSTimer 'time' 问题

ios - UI 测试 : How to find UIBarButtonItem by accessibilityIdentifier with predicate?

ios - xcode 中性能测试的单独方案

iphone - 在 iPhone/iPad 上也可以在网络上提供视频的最佳方式是什么?

iphone - iOS 应用程序在生产时崩溃但在调试时不崩溃

ios - Swift UI 测试 TextField 中的访问字符串