java.lang.ClassCastException: class org.openqa.selenium.Platform$23 cannot be cast to class java.lang.String (org.openqa.selenium.Platform$23 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
See original GitHub issueDescription
Unable to create both IOSDriver and AndroidDriver after upgrading Selenium to 4.2.0 and Appium to 8.1.0. Error message displayed below:
Where creating iOSDriver:
java.lang.ClassCastException: class org.openqa.selenium.Platform$23 cannot be cast to class java.lang.String (org.openqa.selenium.Platform$23 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
at io.appium.java_client.AppiumDriver.ensurePlatformName(AppiumDriver.java:136)
at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:105)
When creating AndroidDriver:
java.lang.ClassCastException: class org.openqa.selenium.Platform$22 cannot be cast to class java.lang.String (org.openqa.selenium.Platform$22 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
at io.appium.java_client.AppiumDriver.ensurePlatformName(AppiumDriver.java:136)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:116)
Notes
- iOSDriver created with Xcuitestoptions
- AndroidDriver created with both DesiredCapabilities and UiAutomator2Options
- Both methods results in the same cannot cast error message above
Environment
- Java client build version or git revision if you use some snapshot: 8.1.0
- Appium server version or git revision if you use some snapshot: 2.0.0-beta.24
- Desktop OS/version used to run Appium if necessary: MacOS Monterey
- Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe:
- Mobile platform/version under test: iOS/Android
- Real device or emulator/simulator: emulator/simulator
Issue Analytics
- State:
- Created a year ago
- Comments:28 (7 by maintainers)
Top Results From Across the Web
selenium - AndroidDriver cant be initialized after mvn clean
String (org.openqa.selenium.Platform$22 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap').
Read more >How to fix java.lang.ClassCastException. - TestingDocs.com
Selenium test that fails with the exception java.lang.ClassCastException: class org.openqa.selenium cannot be cast to class ...
Read more >unable to typecase from webElement to String - Google Groups
Exception in thread "main" java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to java.lang.String. at JavaSelenium.
Read more >[JDK-8204955] Extend ClassCastException message
class p4.c4 cannot be cast to class java.lang.String (p4.c4 is in unnamed module of loader 'MyClassLoader' @<id>; java.lang.String is in module java.base of ......
Read more >ClassCastException "cannot be cast to class java.lang ...
Exception in thread "main" java.lang.ClassCastException: class AsInt cannot be cast to class java.lang.Comparable (AsInt is in unnamed module of loader ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was getting this issue on my Linux machine but not on my local Mac machine. We use Jenkins with Linux slaves pointing to Saucelabs.
The work around was to change from: caps.setCapability(“platformName”, platform); to: caps.setCapability(“appium:platformName”, platform);
It works with no issues so far.
Thanks for the update @n00bstr I’ve created another patch to fix the issue related to platformVersion capability. It turns out Selenium lib tries to add workarounds to browser issues, which badly hits our client: https://github.com/SeleniumHQ/selenium/blob/b0057b54cff7991add4299d58de53245f9d9ecf9/java/src/org/openqa/selenium/AcceptedW3CCapabilityKeys.java#L45