Skip to content

[java-client 5.0.1] java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement #709

Closed

Description

@luisromanbcn

Description

I just tried to update the java-client version from 5.0.0-BETA9 to 5.0.1 and every time I'm trying to find an element in the screen I get this error.
Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:415)

Environment

  • java client build version or git revision if you use some shapshot: 5.0.1
  • Appium server version or git revision if you use some shapshot: 1.6.6-BETA4, 1.6.5
  • Desktop OS/version used to run Appium if necessary: macOS Sierra
  • Mobile platform/version under test: Android 6.0, 5.0
  • Real device or emulator/simulator: Simulator

Activity

  1. TikhomirovSergey commented on Aug 29, 2017

    @TikhomirovSergey
    Contributor

    @luisromanwp Could you share the code sample?

  2. TikhomirovSergey commented on Aug 29, 2017

    @TikhomirovSergey
    Contributor

    @luisromanwp Also. Could you check dependencies of you project? I suspect that there is some artefact which depends on Selenium version < 3.5.x

  3. luisromanbcn commented on Aug 29, 2017

    @luisromanbcn
    Author

    Here is my POM:
    https://gist.github.com/luisromanwp/7781a94d9cb31567540302ca93394e80

    And is failing when I try to find an element like:
    driver.findElement(By.xpath("//*/android.widget.TextView[contains(@text,'Wallapop')]"))

    So, @TikhomirovSergey What should I do to fix it temporally changing dependencies?

  4. TikhomirovSergey commented on Aug 29, 2017

    @TikhomirovSergey
    Contributor

    @luisromanwp

    Could you try
    mvn dependency:tree

    and check the tree?

  5. luisromanbcn commented on Aug 29, 2017

    @luisromanbcn
    Author
  6. luisromanbcn commented on Aug 29, 2017

    @luisromanbcn
    Author

    @TikhomirovSergey

    Finally I made it work doing this in the POM:

    https://gist.github.com/luisromanwp/7389cc9f03a722f3cee9345f3347a0cf

    It was completely a dependency problem, thanks for your help :)

  7. carolcruzc commented on Oct 5, 2017

    @carolcruzc

    @luisromanbcn I cannot see your resolution at the pom.xml link you past here.
    Could you verify it, please.
    I'm taking the same problem

  8. luisromanbcn commented on Oct 5, 2017

    @luisromanbcn
    Author

    @carolcruzc
    Here you have a new link with what I added to the POM to make it work
    https://gist.github.com/luisromanbcn/cf2cab104204e41d74313e287538f2db

  9. carolcruzc commented on Oct 5, 2017

    @carolcruzc
  10. ShriD commented on Feb 8, 2018

    @ShriD

    I am getting the same error on Appium when trying to find element

    Here is the code snippet

    public static MobileElement waitForMobileElementToBeClickable(By by) { try { return (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(by)); } catch(NoSuchElementException nse) { System.out.println("No such element found !"); return null; } catch(TimeoutException toe) { System.out.println("Timeout exception cought !"); return null; } }

    Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement
    [testng] at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:358)

  11. luisromanbcn commented on Feb 8, 2018

    @luisromanbcn
    Author

    @ShriD The problem is that wait.until is a Boolean and you’re trying to convert to MobileElement, you should do a findElement after the code passes the wait.until and return it

  12. added a commit that references this issue on Feb 28, 2018
  13. annq-0196 commented on Jan 1, 2025

    @annq-0196

    I encounter the same issue when finding elements. Not sure if this is a dependency issue or locator issue. Work fine on local but the below error sometime occur on browser stack.
    WebDriver java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class org.openqa.selenium.WebElement
    I'm using java-client 9.2.2, the element locator is:

    @AndroidFindBy(xpath = "//android.widget.EditText[contains(@hint, \"Enter your email, phone\") and @displayed = \"true\"]")
        @iOSXCUITFindBy()
        private WebElement emailField;
    

    Below is the dependency tree

    [INFO] +- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
    [INFO] |  \- junit:junit:jar:4.10:compile
    [INFO] |     \- org.hamcrest:hamcrest-core:jar:1.1:compile
    [INFO] +- io.cucumber:cucumber-java:jar:7.16.1:compile
    [INFO] |  +- io.cucumber:cucumber-core:jar:7.16.1:compile
    [INFO] |  |  +- io.cucumber:cucumber-gherkin:jar:7.16.1:compile
    [INFO] |  |  +- io.cucumber:cucumber-gherkin-messages:jar:7.16.1:compile
    [INFO] |  |  |  \- io.cucumber:gherkin:jar:28.0.0:compile
    [INFO] |  |  +- io.cucumber:messages:jar:24.1.0:compile
    [INFO] |  |  +- io.cucumber:tag-expressions:jar:6.1.0:compile
    [INFO] |  |  +- io.cucumber:cucumber-expressions:jar:17.1.0:compile
    [INFO] |  |  +- io.cucumber:datatable:jar:7.16.1:compile
    [INFO] |  |  +- io.cucumber:cucumber-plugin:jar:7.16.1:compile
    [INFO] |  |  +- io.cucumber:docstring:jar:7.16.1:compile
    [INFO] |  |  +- io.cucumber:html-formatter:jar:21.3.0:compile
    [INFO] |  |  +- io.cucumber:junit-xml-formatter:jar:0.3.0:compile
    [INFO] |  |  \- io.cucumber:ci-environment:jar:10.0.1:compile
    [INFO] |  \- org.apiguardian:apiguardian-api:jar:1.1.2:compile
    [INFO] +- io.cucumber:cucumber-testng:jar:7.16.1:compile
    [INFO] |  \- org.testng:testng:jar:7.9.0:compile
    [INFO] |     +- com.beust:jcommander:jar:1.82:compile
    [INFO] |     \- org.webjars:jquery:jar:3.7.1:runtime
    [INFO] +- io.appium:java-client:jar:9.2.2:compile
    [INFO] |  +- org.seleniumhq.selenium:selenium-api:jar:4.27.0:compile
    [INFO] |  |  \- org.jspecify:jspecify:jar:1.0.0:compile
    [INFO] |  +- org.seleniumhq.selenium:selenium-remote-driver:jar:4.27.0:compile
    [INFO] |  |  +- com.google.auto.service:auto-service-annotations:jar:1.1.1:compile
    [INFO] |  |  +- com.google.guava:guava:jar:33.3.1-jre:compile
    [INFO] |  |  |  +- com.google.guava:failureaccess:jar:1.0.2:compile
    [INFO] |  |  |  +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
    [INFO] |  |  |  +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
    [INFO] |  |  |  +- org.checkerframework:checker-qual:jar:3.43.0:compile
    [INFO] |  |  |  +- com.google.errorprone:error_prone_annotations:jar:2.28.0:compile
    [INFO] |  |  |  \- com.google.j2objc:j2objc-annotations:jar:3.0.0:compile
    [INFO] |  |  +- io.opentelemetry.semconv:opentelemetry-semconv:jar:1.25.0-alpha:compile
    [INFO] |  |  +- io.opentelemetry:opentelemetry-api:jar:1.44.1:compile
    [INFO] |  |  +- io.opentelemetry:opentelemetry-context:jar:1.44.1:compile
    [INFO] |  |  +- io.opentelemetry:opentelemetry-exporter-logging:jar:1.44.1:compile
    [INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-common:jar:1.44.1:compile
    [INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:jar:1.44.1:compile
    [INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:jar:1.44.1:compile
    [INFO] |  |  |  \- io.opentelemetry:opentelemetry-api-incubator:jar:1.44.1-alpha:runtime
    [INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-trace:jar:1.44.1:compile
    [INFO] |  |  +- io.opentelemetry:opentelemetry-sdk:jar:1.44.1:compile
    [INFO] |  |  |  +- io.opentelemetry:opentelemetry-sdk-metrics:jar:1.44.1:compile
    [INFO] |  |  |  \- io.opentelemetry:opentelemetry-sdk-logs:jar:1.44.1:compile
    [INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.15.10:compile
    [INFO] |  |  +- org.seleniumhq.selenium:selenium-http:jar:4.27.0:compile
    [INFO] |  |  |  \- dev.failsafe:failsafe:jar:3.3.2:compile
    [INFO] |  |  +- org.seleniumhq.selenium:selenium-json:jar:4.27.0:compile
    [INFO] |  |  +- org.seleniumhq.selenium:selenium-manager:jar:4.27.0:compile
    [INFO] |  |  \- org.seleniumhq.selenium:selenium-os:jar:4.27.0:compile
    [INFO] |  |     \- org.apache.commons:commons-exec:jar:1.4.0:compile
    [INFO] |  +- org.seleniumhq.selenium:selenium-support:jar:4.27.0:compile
    [INFO] |  +- com.google.code.gson:gson:jar:2.10.1:runtime
    [INFO] |  \- org.slf4j:slf4j-api:jar:2.0.12:compile
    [INFO] +- org.json:json:jar:20240303:compile
    [INFO] +- org.apache.logging.log4j:log4j-core:jar:2.23.1:compile
    [INFO] +- org.apache.logging.log4j:log4j-api:jar:2.23.1:compile
    [INFO] +- commons-io:commons-io:jar:2.16.1:compile
    [INFO] +- commons-codec:commons-codec:jar:1.16.1:compile
    [INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.13:compile
    [INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.13:compile
    [INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
    [INFO] \- org.apache.httpcomponents:httpmime:jar:4.5.13:compile
    
  14. valfirst commented on Jan 2, 2025

    @valfirst
    Collaborator

    @annq-0196 please share the exception stacktrace

  15. annq-0196 commented on Jan 2, 2025

    @annq-0196
  16. valfirst commented on Jan 2, 2025

    @valfirst
    Collaborator

    @annq-0196 unfortunately it's still not clear what root cause is, would you mind sharing Short, Self Contained, Correct (Compilable), Example ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions