Search code examples
iosswiftxcodexctestxcode-ui-testing

How do I identify control center elements in Xcode UI tests?


I managed to open the control center of the device, but i cannot identify the buttons, I need the Wi-Fi one more exactly. I tried with the recorder and it's identified as

app.scrollViews.otherElements.scrollViews.otherElements.switches["Wi-Fi"]

but when I try to run the test again, it fails as it does not find the element. I also tried to find it as other kind of element(buttons or all kinds of bars elements), but nothing works. Also tried to identify it by its label simply using app.buttons["Wi-Fi"] and still no results.

Does anyone know a solution for this?


Solution

  • The control centre is outside the scope of your application under test and therefore cannot be accessed by your UI tests.

    To disable wifi, you need to physically disconnect the device from the Internet, as it's not possible to disconnect from wifi programmatically.