Enable/disable mobile data on iOS devices

The following code provides a solution for disabling mobile data for iOS devices. (The code sample is for XCUITest devices.)

If you want to enable the mobile data, add a wait after the last step and repeat the last line of code.

Copy
Map<String, Object> appName = new HashMap<>();

appName.put("name", "Settings");

driver.executeScript("mobile:application:open", appName);

driver.executeScript("mobile:application:close", appName);     

driver.executeScript("mobile:application:open", appName);



switchToContext(driver, "NATIVE_APP");

driver.findElementByXPath("//XCUIElementTypeCell[@label="Mobile Data"]//*[@label="More Info"]

").click();

driver.findElementByXPath("//XCUIElementTypeSwitch[@label="Mobile Data"]”).click();