Multiple "More" buttons on iPad simulator. How do I narrow it down which one to click (either one)?

huangapple go评论53阅读模式
英文:

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[@&quot;more&quot;];
[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 
&quot;Multiple matching elements found for &lt;XCUIElementQuery: 0x600000c51c20&gt;
...

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 &#39;&quot;more&quot; IN identifiers&#39;
      Output: {
        Key, 0x15e670f80, {{0.0, 1049.0}, {132.0, 60.0}}, identifier: &#39;more&#39;, label: &#39;numbers&#39;
        Key, 0x15e678570, {{546.0, 1049.0}, {98.5, 60.0}}, identifier: &#39;more&#39;, label: &#39;numbers&#39;

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[@&quot;more&quot;] firstMatch] does the trick.

huangapple
  • 本文由 发表于 2023年2月10日 12:07:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406843.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定