Search code examples
xcode8ios-ui-automationaccessibility-inspector

How to tap a toggle button which have label,value and traits as null


Using xcode Ui Automation tool for iOS app, I'm trying create a UI test case. But I got into a situation where a toggle button doesn't have any label value. Due to which UI automation tool is failing to find the element and giving an error.

Is there any other way to select the toggle button. Was thinking of tapping based on co-ordinates, but the co-ordinates vary for different devices.

I've searched thoroughly for an answer but couldn't find one.

Can some one please shed light on this please.

Thanks in Advance !!


Solution

  • According to the best practices, you should add accessibilityIdentifier to the button and use this identifier to select a button. Labels can be changing or can be localized. accessibilityIdentifier are only "visible" for the UI tests.

    You can set accessibilityIdentifier in the Interface Builder or in the code. In the UI tests, you can access element exactly the same as using value.