I am currently trying to automate tests with XCUITest framework for a parking mobile app. The thing is, each time I click on a button, I don't want to click on the static text associated to the element (because the text changes) but on the ID. Is there a way to do that ?
Asked
Active
Viewed 515 times
0
-
1please provide your trial code. – Sagar Bhut Aug 02 '19 at 09:01
-
What do you mean by clicking on the ID instead of the static text ? You can look for static texts with the ID instead of the label – cesarmarch Aug 02 '19 at 12:55
-
Possible duplicate of [iOS XCUITests access element by accessibility](https://stackoverflow.com/questions/41442932/ios-xcuitests-access-element-by-accessibility) – Sfili_81 Aug 29 '19 at 09:43
1 Answers
0
You can match an element by its identifier using matching(identifier:)
function
https://developer.apple.com/documentation/xctest/xcuielementquery/1500679-matching
Chain .firstmatch
or .element
to match the single element.

Roman Zakharov
- 2,185
- 8
- 19
-
This approach might have problems if you have elements without unique Accessibility IDs but containing unique data. – ablarg Sep 14 '19 at 20:27