[java-client 5.0.1] java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement
Closed this issue · 12 comments
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
@luisromanwp Could you share the code sample?
@luisromanwp Also. Could you check dependencies of you project? I suspect that there is some artefact which depends on Selenium version < 3.5.x
@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
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?
@luisromanwp
Could you try
mvn dependency:tree
and check the tree?
Here you have the results:
https://gist.github.com/luisromanwp/bd046f1aad9d3760f93e6ef4abf30153
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 :)
@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
@carolcruzc
Here you have a new link with what I added to the POM to make it work
https://gist.github.com/luisromanbcn/cf2cab104204e41d74313e287538f2db
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