This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3619-207-xcode-ui-testing
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3619-207-xcode-ui-testing
How to tap on specific word of a label in Xcode10 Ui Testing?
is this possible to tap on particular word in a String(Label)? If this is possible please explain me.
Ex:- āI agree to the Terms and Conditions and Privacy Policyā.
The āTerms and Conditionsā string in the above line is not a link, it exists as part of whole āLabelā and I want to tap on specific āTerms and Conditionsā.
@designatednerd Can you please help with this when you get a chance? Thank you - much appreciated! :]
Ooh, thatās a tough one! (Sorry I missed this until now!)
With XCUI itās really going to be difficult because you donāt really have access directly to the label itself, so you canāt really calculate how the label would be laid out, and it would be really difficult to calculate precisely where the tester needs to tap.
Remember that a UI tester is a bit like a blind user, since it canāt really āseeā whatās on the screen and uses all the accessibility APIs that a blind user would in practice. If thereās no way for a blind user to find something, then thereās no way for the UI tester to find it.
Iād recommend starting from there: How would a blind user find it with accessibility APIs? Once you figure that out, you can use those APIs to access it with XCUI.
thanks for your reply.
is it possible to implement tap() on particular word in a String(Label) or not ?
I guess Iāll be a bit more clear than I was previously: Almost certainly not, because thereās no way for the computer to āseeā which words are where on the screen.
Youād need to create some kind of subclass which allowed accessibility to examine labels word by word (which may or may not be what your blind users actually want to do).
Honestly, on iOS, requiring a user to click on a specific part of a label is a bit of an anti-pattern, particularly since the tap targets for single words are going to be really small, and therefore very annoying to try to hit with an actual finger (plus the aforementioned ways it screws up accessibility).
You probably want to consider a different way to do whatever it is youāre doing that doesnāt require such pinpoint accuracy.