4
4
5
5
# Advanced Selectors
6
6
7
+ ## iOS's String Predicates
8
+
9
+ You can specify a [ predicate] ( https://developer.apple.com/documentation/foundation/nspredicate )
10
+ in your Class Chain to limit the number of matched items. There's
11
+ [ a detailed guide to that] ( https://appium.io/docs/en/writing-running-appium/ios/ios-predicate/index.html )
12
+ on the Appium Docs website with some Appium-specific considerations.
13
+
7
14
## iOS's Class Chain Queries
8
15
9
16
Our XCUiTest integration has full support for the 'Class Chain' concept. This
10
- can do much of what XPath does...but faster.
17
+ can do much of what XPath does...but faster. Note that many Class Chains leverage
18
+ String Predicates too.
19
+
20
+ ### String Predicates in Class Chains
21
+
22
+ There's a special array-style syntax for defining predicates in a Class Chain:
23
+
24
+ ```
25
+ // Start with [
26
+ // Followed by `
27
+ // Followed by some text
28
+ // Followed by `
29
+ // End with ]
30
+ [`label != 'a'`]
31
+ [`isWDVisible == 1`]
32
+ [`value < 0`]
33
+ ```
34
+
35
+ Most of the time, you can treat pairs of single quotes or double quotes
36
+ interchangably. If you're searching with a string that contains quote marks,
37
+ though, you'll [ want to be careful] ( https://stackoverflow.com/q/14116217 ) .
38
+
39
+ ``` c
40
+ // Make sure to escape each quote mark that matches your delimiter
41
+ " text with \" some\" 'quote' marks"
42
+ // To NSPredicate, the line above and the line below are equivalent
43
+ ' text with "some" \' quote\' marks'
44
+ ```
45
+ ``` java
46
+ // When defining a iOSXCUITFindBy annotation, you'll be constrained by the
47
+ // Java string-quoting rules too.
48
+ @iOSXCUITFindBy (iOSClassChain = " **/SomeElement[`'text with \" some\" \\\' quote\\\' marks'`]" )
49
+ ```
11
50
12
51
### External References
13
52
@@ -20,11 +59,19 @@ to learn more about the general concept.
20
59
// Selector for image elements
21
60
@iOSXCUITFindBy (iOSClassChain = " **/XCUIElementTypeImage" )
22
61
23
- // Selector for every cell with the name 'Foo'
62
+ // Selector for every cell with the name 'Foo' (single quote style)
63
+ @iOSXCUITFindBy (iOSClassChain = " **/XCUIElementTypeCell[`name == 'Foo'`]" )
64
+ // Selector for every cell with the name "Foo" (double quote style)
24
65
@iOSXCUITFindBy (iOSClassChain = " **/XCUIElementTypeCell[`name == \" Foo\" `]" )
25
- // Selector for every cell with a name that starts with 'Foo'
66
+
67
+ // Selector for every cell with a name that starts with 'Foo' (single quote style)
68
+ @iOSXCUITFindBy (iOSClassChain = " **/XCUIElementTypeCell[`name BEGINSWITH 'Foo'`]" )
69
+ // Selector for every cell with a name that starts with "Foo" (double quote style)
26
70
@iOSXCUITFindBy (iOSClassChain = " **/XCUIElementTypeCell[`name BEGINSWITH \" Foo\" `]" )
27
71
72
+ // Selector for every cell with a name that starts with "it's not"
73
+ @iOSXCUITFindBy (iOSClassChain = " **/XCUIElementTypeCell[`name BEGINSWITH \" it's not\" `]" )
74
+
28
75
// Selector that'll match every top-level element on screen
29
76
@iOSXCUITFindBy (iOSClassChain = " *" )
30
77
// Selector that'll match every leaf element on screen (watch out: this can be SLOW)
0 commit comments