XCUIElementTypeSwitch errors setting value - Keyboard not present

Hi. When setting the value of an iOS switch, I get this error. The switch does set from false to true, but then I get this exception about Keyboard not present and the test cannot move on.

This was working fine for Appium 1.5.3, but errors looking for keyboard with 1.6.4 (XCUITest).
I have tried both of these commands.

		.elementByAccessibilityId('gift_switch').sendKeys(1)
		.elementByAccessibilityId('gift_switch').setImmediateValue(1)

Error: [element.sendKeys(1)] Error response status: 13, UnknownError - An unknown server-side error occurred while processing the command. Selenium error: An unknown server-side error occurred while processing the command. Original error: Error Domain=com.facebook.WebDriverAgent Code=1 "Keyboard is not present" UserInfo={NSLocalizedDescription=Keyboard is not present}

Yes, I could just click on the switch, but I was able to set it to whatever the test was expecting, rather than clicking on it to make it the “opposite” status of what it was. Anyone else able to set XCUIElementTypeSwitch control using values?

i use just tap on switch to change it value with XCUITest

Tap will work, but Tap will only set it to opposite of what it is. This is fragile. If I need the switch to be on for the test, then I will have to write a method to say of the Switch it false, click on it to set it to true, otherwise don’t click on it. So much easier and less code to just set it to True like I had been doing.

fragile but working :slight_smile: . i use just same as you mentioned logic - read state and decide tap or not.

Do you have an example of how you verify the switch has a value of 0 or 1?

i am just reading it value. in our application it changes when we switch on/off with true/false string values.

    public boolean getContactlessSwitch() {
        System.out.println("  get 'Contactless' switch value");
        try {
            return Boolean.parseBoolean(cellSwitchControl.get(0).
                    findElement(MobileBy.className("XCUIElementTypeSwitch")).getAttribute("value"));
        } catch (Exception e) {
            return false;
        }
    }