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"))
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358

1 Answers1

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)
Joe Masilotti
  • 16,815
  • 6
  • 77
  • 87
  • Maybe you know the answer for this also?:-) http://stackoverflow.com/questions/32522465/how-to-open-url-in-safari-and-the-get-back-to-the-app-under-uitests-in-xcode-7 – Bartłomiej Semańczyk Sep 11 '15 at 11:41
  • can use `identifier` instead of `label` if you use the accessibility identifier instead of the label – Fonix Aug 30 '18 at 14:31