I am trying to tap the More
button in a XCUITest:
XCUIElement* moreKey = self.app.keys[@"more"];
[moreKey tap];
and on iPhone simulator it works fine, but on iPad simulator it crashes when I try to tap it:
Failed to Error Domain=com.apple.dt.xctest.ui-testing.error Code=10006
"Multiple matching elements found for <XCUIElementQuery: 0x600000c51c20>
...
The issue is that it finds multiple instances of the "More" button on iPad (which, unlike iPhone, it has two of):
...}
↪︎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'
So, it doesn't seem to know which one to click.
I found similar questions, but for custom buttons, where solution was to make their identifier unique. That's not applicable for Apple's own "More" key, the identifier of which I do not control.
How do I fix it?
Can I apply elementBoundByIndex:
here somehow?
XCUIElement* moreKey = [self.app.keys[@"more"] firstMatch]
does the trick.