Reputation: 563
first day using NSPredicates with Appium.
Here is the issue.
I have 3 XCUIElementTypeTextField elements inside the view.
I can use Xpath to select using like this
"(//XCUIElementTypeTextField)[1]"
then 2 and 3. However Xpath is slow and I'm now using NsPredicates when I need a more complex solution. While I know that I could search by other strategies does NSPredicate support selectors like the xpath one above? Could I do:
"SUBQUERY(*, $el, $el.type == 'XCUIElementTypeTextField')[0]"
this doesn't return a result however:
"type =='XCUIElementTypeTextField'"
does.
Upvotes: 1
Views: 935
Reputation: 3658
NSPredicate is basically the way of defining logical conditions, Xpath is a language for searching XML.
I'm pretty sure you already checked, but maybe for others to get more knowledge about what you can do with NSPredicate check official source
Still more important to check what works with Appium: NSPredicate-based locators listed in XCUIModeTest.java and find_by_ios_predicate_tests.py
As a workaround for your case you can get a list of elements using your predicate and iterate through it later to get the needed one by index.
Upvotes: 1