-
ACCESSIBILITY ID
-
CLASS NAME
-
IOS PREDICATE STRING
-
IOS CLASS CHAIN
-
XPATH
-
ID -- usually equivalent to Accessibility ID if there is one
-
NAME -- can be very slow because it searches all name attributes when used by itself
- choose the best selector strategy
- sometimes it's not always obvious
- test out different selectors
- find something easy to locate to reduce the tree size
- build predicates / class chains that eliminate variables
- the order of class chain elements matters
- start with easy to prune rules
- sometimes (rarely) multiple queries can be faster
- getting all the elements in a group and then filtering client side
- use indexes when it makes sense or doesn't matter (e.g. first, last)
-
usually the best option
-
unique
-
efficient to search for
-
the only strategy that work the same cross platform
-
uses "content desc" property on Android
$('~my_accessibility_id')
-
equivalent to tag name for HTML
-
usually not unique
-
fast to search
-
can be used to get a collection for secondary search
$('XCUIElementTypeStaticText')
- combine simple critera to form more complex matches
- native Javascript search strategy -- built into IOS
- usable in IOS 10+ using '-ios predicate string' locator strategy
- more efficient than XPath
- (because XML has to be generated and then deserialized to map to )
- Predicate expressions are executed in the same order listed
Properties:
- name
- value
- label
- type
- visible
- enabled
- rect
complex predicate example
type == 'XCUIElementTypeStaticText'
AND value BEGINSWITH[c] 'Ncc Auto Five'
AND name CONTAINS 'bar'
AND visible == 1
webdriver.io locator
$('-ios predicate string:' +
'type==XCUIElementTypeStaticText' + ' && ' +
'name==title_label' ' && ' +
'label CONTAINS "Ncc Auto" &&' +
)
- built into Appium
- similar to XPath but more efficient
- less functionality
- ability to refer to elements by index
- good for hierarchical location
- allows attributes
- search for CONTAINS, BEGINSWITH
webdriverio example:
$('-ios class chain:' +
'**/XCUIElementTypeStaticText[`name == "title_label"`]'
)
- least efficient
- because of serialization
- slowest on IOS
- specific over general
- good for index
- can get siblings and parent
example:
//XCUIElementTypeStaticText[@name="title_label"][1]
https://appiumpro.com/editions/8
http://appium.io/docs/en/writing-running-appium/ios/ios-predicate/#ios-predicate
https://github.com/facebookarchive/WebDriverAgent/wiki/Predicate-Queries-Construction-Rules
https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules
https://webdriver.io/docs/selectors.html
https://github.com/facebookarchive/WebDriverAgent/wiki/How-To-Achieve-The-Best-Lookup-Performance