Appium iOS iOSNsPredicate 评估多个元素如何指定其中之一?

Appium iOS iOSNsPredicate evaluates to multiple elements how to specify one of them?

假设我在 Appium UI 测试中有以下移动元素:

@iOSXCUITFindBy(iOSNsPredicate = "name = 'Enter Address'")
private MobileElement enterAddress;

如果 iOSNsPredicate 评估为多个元素,我如何对其应用索引,以便脚本点击特定的移动元素?

默认情况下它只点击结果列表中的第一个,但有时它不是正确的。所以我想知道我们是否可以用来单击第一个以外的另一个? 谢谢

您可以使用 iOSClassChain 而不是 iOSNsPredicate 来做到这一点。例如

**/XCUIElementTypeAny[`name == "Enter Address"`][2]

会 select 具有相同名称的第二个元素,就像您的问题所建议的那样。索引从 1 开始。

文档中有更多详细信息Class Chain Queries Construction Rules