0

I referred to one of the answers posted in this forum and when I attempted to run following code

    NetworkConnection mobileDriver = (NetworkConnection) appiumDriver;
   if (mobileDriver.getNetworkConnection() != ConnectionType.AIRPLANE_MODE) {
      // enabling Airplane mode
      mobileDriver.setNetworkConnection(ConnectionType.AIRPLANE_MODE);
    }

I get following exception:

java.lang.ClassCastException: io.appium.java_client.ios.IOSDriver cannot be cast to org.openqa.selenium.mobile.NetworkConnection

Here is the link to the post which I had referred to How can I switch ON/OFF AIRPLANE mode and wifi using Appium?

  • Provide a link in your original post to the post in this forum from where you got this information. – Bill Hileman Jun 5 at 18:37
  • @BillHileman I have provided the link in my post. – UserCS Jun 5 at 20:01
  • That was helpful, thanks. I believe the last offered answer to your original post answers your question: it is currently not possible to do what you want in ios, only android. You probably should have continued this in your original post instead of starting a new one. As the original offerer of the solution you attempted why it doesn't work, I don't recognize the method. Notice his example has the driver pre-defined as a static AppiumDriver before casting it, though. – Bill Hileman Jun 5 at 20:08
  • static doesn't work here is my code: public static void turnWifiOff() throws InterruptedException { NetworkConnection mobileDriver = (NetworkConnection) appiumDriver; if (mobileDriver.getNetworkConnection() != ConnectionType.AIRPLANE_MODE) { // enabling Airplane mode mobileDriver.setNetworkConnection(ConnectionType.AIRPLANE_MODE); } } – UserCS Jun 5 at 20:56
0

iOS doesn't support NetworkConnection, so to turn off wifi, you can open the Control Center, you can do that with

public static void openControlCenter() throws InterruptedException

        {
            new TouchAction(DriverConfig.getInstance().getDriver()).press(point(250, 735)).waitAction(waitOptions(Duration.ofSeconds(3))).moveTo(point(250, -460)).release()
                    .perform();
            DriverConfig.getInstance().getDriver().findElement(By.name("wifi-button")).click();
            DriverConfig.getInstance().getDriver().findElement(By.xpath("//XCUIElementTypeWindow[2]/XCUIElementTypeOther[2]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]")).click();
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.