question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Description

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:closed
  • Created a year ago
  • Comments:28 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
cyberjaime45commented, Jun 4, 2022

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.

4reactions
mykola-mokhnachcommented, Jun 2, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found