Appium: How to resolve Class cast exception for iOS driver? "java.lang.ClassCastException"



  • 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?



  • 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();
            }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2