Huibin Zhang
Huibin Zhang

Reputation: 1110

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

Say I have following mobile element in Appium UI test:

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

in case the iOSNsPredicate evaluates to multiple elements, how can I apply an index to it, so that the scripts will click a specific mobile element?

by default it only click the first one in the result list, but sometimes it is not the correct one. So I want to know if anyway we can use to click one other than the first one? Thanks.

ue

Upvotes: 0

Views: 1423

Answers (1)

hirvovi
hirvovi

Reputation: 41

You can do that using iOSClassChain instead of iOSNsPredicate. For example

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

would select the second element with that same name, like your question suggests. Index starts at 1.

More details in documentation Class Chain Queries Construction Rules

Upvotes: 1

Related Questions