Skip to content

java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement #286

@aeroclee

Description

@aeroclee

Hello All,

I have ClassCastException issue like following error:
java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement.

I could only refer an element by WebElement, but I am having ClassCastException issue using Mobile Reference. I am trying to use an element by AutomationId (AccessibilityID). I believe this is most stable way to locate an element in WinAppDriver.

Please correct me if there is something I miss or misunderstand? Please let me know.
Thanks.

Here is pom.xml file info:
<appium.version>5.0.4</appium.version>
<selenium.version>3.6.0</selenium.version>

io.appium
java-client
${appium.version}


org.seleniumhq.selenium
selenium-java
${selenium.version}

Here is how I define WinAppDriver:
protected static WindowsDriver driver;
// Also tried with protected static WindowsDriver<? extends MobileElement> driver;

caps.setCapability(MobileCapabilityType.APP, ConfigHelper.getInstance().app);
this.driver = new WindowsDriver<>(getLocalAddressURL(), caps);
return this.driver;

// OK with WebElement
WebElement title = driver.findElementByAccessibilityId("Title");

List listAirportInfo = (List)driver.findElementsByName("DataModel.Name");
WebElement code = ((WebElement)listAirportInfo.get(0)).findElement(By.className("Block"));

Case1: using findElementsByName
// CastException when I execute on the bold line: MobileElement.
List listsTypeNames = (List) driver.findElementsByName("DataContextItem");
String name = listsTypeNames.get(0).findElementByAccessibilityId("Selector_Text_Name").getText();

Case2: using findElementsByClassName
List listsTypeNames = (List) driver.findElementsByClassName("Item");
MobileElement chartTypeName = ((MobileElement)listsTypeNames.get(0)).findElementByAccessibilityId("Selector_Text_Name");
String name = chartTypeName.getText();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions