Appium IOS - How to use MobileBy

I am working on
Appium - 2.11.5
xcuitest - 7.1.
IOS - 17.5

I have a scenarios to toggle Airplane mode in IOS
looking for help if this is possible via appium.
Any help in this regards is appreciated.

I am ablto load the setting up and can see Airplane mode button and toggle option
Tried multiple options
clickOnElement(stepUtils.getWebElementByXpath(“((//[@name = ‘Airplane Mode’])/following-sibling::)[1]”))

MobileBy.xpath(“//XCUIElementTypeSwitch[@name=‘Airplane Mode’]”).click()

Nothing works

So MobileBy is just to identify the element. You have to actually interact with element using driver as such:

By airplaneModeSwch = MobileBy.xpath(“//XCUIElementTypeSwitch[@name=‘Airplane Mode’]”);
driver.findElement(airplaneModeSwch).click();

Alternatively, 1 line:
driver.findElement(MobileBy.xpath(“//XCUIElementTypeSwitch[@name=‘Airplane Mode’]”)).click();

Java client github has examples using AppiumBy:

More on AppiumBy in migration docs:

no issue with

driver.findElement(AppiumBy.iOSNsPredicateString("type == 'XCUIElementTypeSwitch' AND name == 'Airplane Mode'")).click();

48c0c7c467287785_1