英文:
Multiple "More" buttons on iPad simulator. How do I narrow it down which one to click (either one)?
问题
在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上找到了多个“More”按钮的实例(与iPhone不同,iPad上有两个):
...
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'
}
因此,它似乎不知道应该点击哪一个。
我找到了类似的问题,但是对于自定义按钮,解决方案是使它们的标识符唯一。这对于苹果自己的“More”键不适用,因为我无法控制它的标识符。
我应该如何解决这个问题?我是否可以在这里应用elementBoundByIndex:
?
英文:
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?
答案1
得分: 1
XCUIElement* moreKey = [self.app.keys[@"more"] firstMatch]
完成这项任务。
英文:
XCUIElement* moreKey = [self.app.keys[@"more"] firstMatch]
does the trick.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论