我正在尝试点击 XCUITest 中的
More
按钮:
XCUIElement* moreKey = self.app.keys[@"more"];
[moreKey tap];
在 iPhone 模拟器上它工作正常,但在 iPad 模拟器上,当我尝试点击它时它崩溃了:
Failed to Error Domain=com.apple.dt.xctest.ui-testing.error Code=10006
"Multiple matching elements found for <XCUIElementQuery: 0x600000c51c20>
...
问题在于它在 iPad 上找到了多个“更多”按钮实例(与 iPhone 不同,它有两个):
...}
↪︎Find: Elements matching predicate '"more" IN identifiers'
Output: {
Key, 0x15e670f80, {{0.0, 1049.0}, {132.0, 60.0}}, identifier: 'more', label: 'numbers'
Key, 0x15e678570, {{546.0, 1049.0}, {98.5, 60.0}}, identifier: 'more', label: 'numbers'
所以,它似乎不知道该点击哪一个。
我发现了类似的问题,但对于自定义按钮,解决方案是使其标识符唯一。这不适用于苹果自己的“更多”键,我无法控制其标识符。
如何解决? 我可以在这里申请
elementBoundByIndex:
吗?
XCUIElement* moreKey = [self.app.keys[@"more"] firstMatch]
就可以了。