You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java-client 5.0.1] java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement #709
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
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)
@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
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;
Activity
TikhomirovSergey commentedon Aug 29, 2017
@luisromanwp Could you share the code sample?
TikhomirovSergey commentedon Aug 29, 2017
@luisromanwp Also. Could you check dependencies of you project? I suspect that there is some artefact which depends on Selenium version < 3.5.x
TikhomirovSergey commentedon Aug 29, 2017
@luisromanwp
Yes. It looks like there is the dependency conflict.
It was in the older version
https://github.com/SeleniumHQ/selenium/blob/91f9f2a6194a9c33006e9415c1f257c6a1fa5c04/java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java#L415
This is how it is looking now:
https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java#L415
luisromanbcn commentedon Aug 29, 2017
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?
TikhomirovSergey commentedon Aug 29, 2017
@luisromanwp
Could you try
mvn dependency:treeand check the tree?
luisromanbcn commentedon Aug 29, 2017
@TikhomirovSergey
Here you have the results:
https://gist.github.com/luisromanwp/bd046f1aad9d3760f93e6ef4abf30153
luisromanbcn commentedon Aug 29, 2017
@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 :)
carolcruzc commentedon Oct 5, 2017
@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
luisromanbcn commentedon Oct 5, 2017
@carolcruzc
Here you have a new link with what I added to the POM to make it work
https://gist.github.com/luisromanbcn/cf2cab104204e41d74313e287538f2db
carolcruzc commentedon Oct 5, 2017
ShriD commentedon Feb 8, 2018
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)
luisromanbcn commentedon Feb 8, 2018
@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
Add LocalAppiumAppTest
annq-0196 commentedon Jan 1, 2025
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.WebElementI'm using java-client 9.2.2, the element locator is:
Below is the dependency tree
valfirst commentedon Jan 2, 2025
@annq-0196 please share the exception stacktrace
annq-0196 commentedon Jan 2, 2025
@valfirst here is the log
excp_stack_trace.txt
valfirst commentedon Jan 2, 2025
@annq-0196 unfortunately it's still not clear what root cause is, would you mind sharing Short, Self Contained, Correct (Compilable), Example ?