How to find button with predicate under UITests in Xcode7?
Asked Answered
S

1

8

I need to access following button:

enter image description here

This line works fine:

app.buttons["Reorder 1, $27 000, LondonStreet, ok, Pending"]

but this don't:

app.buttons.elementMatchingPredicate(NSPredicate(format: "accessibilityTitle BEGINSWITH[cd] %@", "Reorder 1"))
Shaun answered 11/9, 2015 at 9:57 Comment(0)
S
22

When finding elements via predicates you must use the XCUIElementAttributes Protocol. For this example, I don't think title will actually work, but try using label (which should map to accessibilityLabel).

For some reason the %@ format option doesn't seem to work in Swift. Also note the extra single quotes around "Reorder 1".

let predicate = NSPredicate(format: "label BEGINSWITH[cd] 'Reorder 1'")
let button = app.buttons.elementMatchingPredicate(predicate)
Supportive answered 11/9, 2015 at 10:38 Comment(2)
Maybe you know the answer for this also?:-) #32522965Kenleigh
can use identifier instead of label if you use the accessibility identifier instead of the labelObsidian

© 2022 - 2024 — McMap. All rights reserved.