java.lang.ClassCastException error on mobile iOS test

I am trying to make an automated test suite for a mobile app on iOS. The code is written down in Javascript using Titanium framework, which is actually making it very difficult to identify the elements. I’m using Java on IntelliJ, Appium server 1.7.0 (since I the app desktop is not compatible yet with Xcode 9).

I have the following libraries installed in my project:
-java-client-4.1.2 (I am aware that there’s a 5.0.3 version, but the driver is set to null in this case, not precisely sure what version I should use).

The following is my code:

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;


public class LoginTest {

private IOSDriver driver;

public void setUp() throws MalformedURLException {

    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability("platformName", "iOS");
    capabilities.setCapability("deviceName", "iPhone 6s");
    capabilities.setCapability("platformVersion", "10.3");
    capabilities.setCapability("app", "/Users/themermaid/Downloads/");
    capabilities.setCapability("deviceOrientation", "portrait");
    capabilities.setCapability("appiumVersion", "1.7.0");

    driver = new IOSDriver(new URL(""), capabilities);

public void tearDown(){

public void loginWrongPassword() {
    IOSElement next = (IOSElement) driver.findElementByAccessibilityId("nextButton");;;
    IOSElement email = (IOSElement) driver.findElementByXPath("//XCUIElementTypeStaticText[@name='Email']");;
    email.sendKeys("[email protected]");
    MobileElement password = (MobileElement) driver.findElementByXPath("//XCUIElementTypeStaticText[@name='Password']");;
    MobileElement login_button = (MobileElement) driver.findElementByXPath("//XCUIElementTypeStaticText[@name='Login']");;
    MobileElement warning = (MobileElement) driver.findElementsByPartialLinkText("wrong username / password"); //missing way to find warning element


I’m getting the following exception:

java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.ios.IOSElement

at LoginTest.loginWrongPassword(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)...

if I do a swipe instead of finding the element, the touch action is performed. I cannot, however, find elements in any way. I don’t have any options either asides from accessibility ids or path, but this seems to be like a problem with the client. I’m out of ideas at this point on how to go on, so I’d ve very grateful if you could help me out on this.

Thank you in a advance .

Could anybody help me on this?

I found out that if I Use RemoteWebElement instead of iOS or Mobile Element, then it finds the elements and clicks on them, but then I cannot perform mobile touch actions, such as swiping or long pressing.

I am also having this same issue with using WindowsElement. I have yet to get this resolved. I’m using winapp with the java_client. Any thoughts on this?