I’m working on a codebase which will work on all platform(e.g. Android, iOS and The Web, The app has Webview in it).
I’m creating drivers as below
AppiumDriver<MobileElement> appiumDriver = new AndroidDriver<MobileElement>(newURL("http://0.0.0.0:4723/wd/hub"), desiredCapabilities);
or AppiumDriver<MobileElement> appiumDriver = new IOSDriver<MobileElement>(newURL("http://0.0.0.0:4723/wd/hub"), desiredCapabilities);
When I reach to a webview page, I switch to the webview context. The issue starts at this point.
There is a Select element , How do find/interact with the element. When I try to cast the element to Select as below
((Select)selectElement).selectByValue("2")
I get “Cannot cast 'io.appium.java_client.android.AndroidElement$$EnhancerByCGLIB$$b598166c' to 'org.openqa.selenium.support.ui.Select'” excetption.
If I change the element to WebView I get “```Can not cast AndroidElement to WebElement”(something like this) and similar issue if I try to Cast AppiumDriver to WebDriver.
I have checked the java client doc and it says here that MobileElement implements the WebElement interface.
Why is this not working and what is the solution for this?
java.lang.ClassCastException: io.appium.java_client.android.AndroidElement$$EnhancerByCGLIB$$b598166c cannot be cast to org.openqa.selenium.support.ui.Select
at pages.PaymentPage.setExpirationMonth(PaymentPage.java:133)
at com.tw.test.ios.ShoppingTest.test1(ShoppingTest.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
can you check if you are able to cast Mobile element to “Select” element?
let me know if you any other detail.
It is Still not working for me, getting the same error. which version of Appium and Java client are you using?
I’ve tried with
JavaClient : tried 5.0.0beta9, 5.0.1, 5.0.2, 5.0.3
Appium sever: 1.6.5
Thanks, @Aleksei for all the help.
It seems Something is incorrect in the way I have implemented the framework, but not sure where. I’ll review my code and try to find the issue.