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:
-client-combined-3.5.3-nodeps
-selenium-server-standalone-3.5.3
-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;

import java.net.MalformedURLException;
import java.net.URL;

public class LoginTest {

private IOSDriver driver;

@Before
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/xxx.app");
    capabilities.setCapability("deviceOrientation", "portrait");
    capabilities.setCapability("appiumVersion", "1.7.0");

    driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
    driver.launchApp();
}

@After
public void tearDown(){
    driver.quit();
}

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

}

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(LoginTest.java:57)
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.

Hi,
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?