I would like to click an element without user input. I see it's possible in XCUIElement which is a part of the XCTest framework to ensure things are working correctly, and I'm aware of various other testing frameworks that support E2E testing with simulated clicks. But is it possible to trigger this in production outside of testing? E.g. How app remotes work for a TV - pressing a button on the app will move right, left, or click an object on the TV (only remove the TV from this question and have it target the OS it's running on)
Accepted Reply
I don't think you can access another app due to sandboxing and other security measures.
It might be easier to just call the event handler yourself, but you can trigger an event on a control.
https://stackoverflow.com/questions/4028734/how-to-programmatically-fake-a-touch-event-to-a-uibutton
That is a little old, but it should work, depending on the type of control involved. There isn't a single way to simulate events though because of differences in the controls.
-
Awesome, thanks that should work!
Replies
Do you mean inside the app that you want to trigger the click in? Or another app?
-
Both if possible, so inside the app (which maybe could be done by setting the focus in accessibility mode?), and then at the OS level (so while navigating the OS to select an app, text someone, check your settings, etc..). And then third option which I'm not sure would be even possible given security/permissions of other apps, and how other apps handle it, but navigating inside another app from a picture-in-picture (when it looks minimized on your phone/tablet) view of the current app
I don't think you can access another app due to sandboxing and other security measures.
It might be easier to just call the event handler yourself, but you can trigger an event on a control.
https://stackoverflow.com/questions/4028734/how-to-programmatically-fake-a-touch-event-to-a-uibutton
That is a little old, but it should work, depending on the type of control involved. There isn't a single way to simulate events though because of differences in the controls.
-
Awesome, thanks that should work!