grey_accessibilityLabel("Login") 与 UI 层次结构中具有相同辅助功能标签的元素不匹配

grey_accessibilityLabel("Login") doesn't match element that exists in UI hierarchy with the same accessibility label

我正在使用此代码点击登录按钮:

[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel("Login")] performAction:grey_tap()];

但是,它失败并出现以下错误:

No elements found

失败时转储的 UI 层次结构中的相关元素如下所示:

<UIButton:0x7fcb01d963d0; AX=N; AX.label='Login'; AX.frame={{16, 64}, {124, 64}}; AX.activationPoint={78, 96}; AX.traits='UIAccessibilityTraitLink'; AX.focused='N'>

点击登录按钮的正确方法是什么?

我加了AX=N matching to the EarlGrey FAQ.

How do I match elements that are denoted with "AX=N" in the view hierarchy?

EarlGrey's view hierarchy identifies non-accessible elements with AX=N. Accessibility IDs can be added to both accessible and non-accessible elements. When searching for AX=N elements, the following accessibility matchers won't work:

  • grey_accessibilityLabel
  • grey_accessibilityValue
  • grey_accessibilityTrait
  • grey_accessibilityHint

If the AX=N element can't be matched by grey_accessibilityID, then you'll have to use non-accessibility matchers to locate the element.

我会修复按钮,使其可以访问,然后标签匹配器就会工作。