Repository navigation
can't find element when use 5.0.0 beta1,wrong:"java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement" #552
Description
Description
when I use 5.0.0beta1 java-client,I can't find any element.the wrong is:
java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement
Environment
- java client build version or git revision if you use some shapshot:5.0.0 beta1 from maven
- Appium server version or git revision if you use some shapshot:1.6.0 and 1.6.3
- Mobile platform/version under test:ios 10.2,xcode 8.2.1
- Real device or emulator/simulator:real
Details
public class Test {
private IOSDriver<MobileElement> driver = null;
@BeforeClass
public void beforeclass() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "IOS");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "111");
capabilities.setCapability(MobileCapabilityType.APP, "my app");
capabilities.setCapability(MobileCapabilityType.UDID, "my udid");
try {
driver = new IOSDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Test
public void element() throws InterruptedException {
Thread.sleep(10000);
MobileElement element = (MobileElement) driver.findElement(By.className("XCUIElementTypeScrollView"));
element.getSize();
Thread.sleep(10000);
}
@AfterClass(alwaysRun = true)
public void afterclass() {
driver.quit();
}
}
Ecxeption stacktraces
FAILED: element
java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement
at com.haimi.HMLibrary.keywords.swipeTest.element(swipeTest.java:52)
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:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
Link to Appium logs
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/6B9292D7-5B44-488B-9D68-5D8B90899294/element] with body: {"using":"class name","value":"XCUIElementTypeScrollView"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"ELEMENT":"22FC9416-0EB1-47CB-A800-019C566EC450","type":"XCUIElementTypeScrollView","label":null},"sessionId":"6B9292D7-5B44-488B-9D68-5D8B90899294","status":0}
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"22FC9416-0EB1-47CB-A800-019C566EC450","type":"XCUIElementTypeScrollView","label":null}
Activity
derunewige commentedon Jan 3, 2017
I have exactly the same issue.
Appium version (or git revision) that exhibits the issue: 1.6.1-beta
Desktop OS/version used to run Appium: OS X 10.12.2
Node.js version (unless using Appium.app|exe): 6.9.1
Mobile platform/version under test: iOS 10.0
Real device or emulator/simulator: simulator
Appium CLI or Appium.app|exe: Appium CLI
Coding language: java-client 5.0.0-BETA1
I am upgrading from iOS 9.3 to 10.0. So I changed to xcode8 and got the new java-client.
I was frighten to have lot of problems with the migration from the uiautomation to the NSPredicats, but first there occurs some strange cast errors.
The last line with .click() leads to the following error:
org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.ios.IOSElementAnd also in a for each loop this error occurs
Debugging shows me, that "driver.findElementsByAccessibilityId" returns a List of RemoteWebElements (screenshot01 + 02)


Why do I get RemoteWebElements from my AppiumDriver ?
TikhomirovSergey commentedon Jan 3, 2017
@derunewige
@iriszhang1986
Guys, could you invoke the
and show the result map here?
TikhomirovSergey commentedon Jan 3, 2017
It is defenetely the bug but now I'm trying to get my local Mac machine fixed
derunewige commentedon Jan 3, 2017
At which place in the code?
saikrishna321 commentedon Jan 3, 2017
@derunewige
derunewige commentedon Jan 3, 2017
@TikhomirovSergey
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.0");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 7");
caps.setCapability(MobileCapabilityType.APP, "/Users/username/appname.app");
caps.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "xx.xxxx.XXX");
caps.setCapability(IOSMobileCapabilityType.AUTO_ACCEPT_ALERTS, Boolean.TRUE);
caps.setCapability(IOSMobileCapabilityType.SEND_KEY_STRATEGY, SendKeyStrategy.SET_VALUE);
caps.setCapability(MobileCapabilityType.NO_RESET, Boolean.TRUE);
caps.setCapability(MobileCapabilityType.FULL_RESET, Boolean.FALSE);
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
log.debug("Before printing session details");
log.debug(driver.getSessionDetails());
log.debug("After printing session details");
TikhomirovSergey commentedon Jan 3, 2017
@derunewige @saikrishna321 @SrinivasanTarget
It seemst that there are two problems.
The first problem is that we didn't expect that session can't contain any information about platform/automation. I think we can resolve it on the client side.
The second probled. Why does it not contain that info when app is started on a real iPhone/iPad? May be there is server side bug.
Any thoughts?
saikrishna321 commentedon Jan 3, 2017
@TikhomirovSergey
All the details are received from server including the automation and platform and lot more. Sample response
let me try on real device
SrinivasanTarget commentedon Jan 3, 2017
I see
Automation NameorPlatform Detailsis not coming up in session details at times when we run on XCUITMode (Only in XCUITMode) even on simulators.SrinivasanTarget commentedon Jan 3, 2017
@iriszhang1986 @derunewige Please do a run without below capabilities and send us entire server logs.
Between i'm debugging it as well.
saikrishna321 commentedon Jan 3, 2017
@SrinivasanTarget @TikhomirovSergey with legacy driver i get the below response, which looks fine to me. May be as srini mentioned could be with XCUITest
{"webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"networkConnectionEnabled":false,"app":"/Users/saikrisv/Downloads/XXX-debug.ipa","bundleId":"XXX","udid":"XXXXX","platformName":"iOS","deviceName":"iPhone SE","platformVersion":"9.3.2","desired":{"app":"/Users/saikrisv/Downloads/XXX-debug.ipa","bundleId":"XXX","udid":"XXX","platformName":"iOS","deviceName":"iPhone SE","platformVersion":"9.3.2"}}
SrinivasanTarget commentedon Jan 3, 2017
Yes it is fine in legacy driver and UIAutomator2 mode but
Automation Nameis not coming if we didn't specify it explicitly in desired caps and running on iOS10 sims.1 remaining item
derunewige commentedon Jan 4, 2017
Good morning!
here is the server log without these four caps: gist
So it is only:
Console log:
It is interesting, that without that four caps the browser name, or rather the app name, as well as the bundleID is not set when calling getSessionDetails()
derunewige commentedon Jan 4, 2017
I did an update from appium 1.6.1-beta to 1.6.3 and now it looks like it is working!
SrinivasanTarget commentedon Jan 4, 2017
@derunewige Can you attach the latest logs as well here (1.6.3)?
derunewige commentedon Jan 4, 2017
Yes, of course: gist
Thank you all for your support!
saikrishna321 commentedon Jan 4, 2017
@derunewige now it gets all the session details, @TikhomirovSergey can we keep this open as @SrinivasanTarget did see the session details missing on random calls
SrinivasanTarget commentedon Jan 4, 2017
Yes @saikrishna321. Session details is a server issue but anyways we need a fix for this which @TikhomirovSergey is working on.
TikhomirovSergey commentedon Jan 4, 2017
@derunewige @sravanmedarapu @saikrishna321
There is Installing-the-project. We recommend 1.6.3 or higher.
@SrinivasanTarget are session details missed randomly with 1.6.3?
@saikrishna321 If no, we can close this issue, if yes I will keep working on the fix. We could use capabilities if session details are missed.
SrinivasanTarget commentedon Jan 4, 2017
@SrinivasanTarget are session details missed randomly with 1.6.3? >> It is missing only if you dont specify the Automation Name explicitly and run on iOS 10.
saikrishna321 commentedon Jan 4, 2017
@TikhomirovSergey we need to keep this open and get the session details fixed if AutomationName is provided or not when running on iOS 10.
What say @SrinivasanTarget ?
SrinivasanTarget commentedon Jan 4, 2017
Merge pull request #556 from TikhomirovSergey/master
fionazj commentedon Jun 5, 2017
Hey guys, any solution for this ? I met same problem... and my environment are as follow:
Appium: 1.6.4
Selenium/Grid: 3.2.0
Java-client: 5.0.0 BETA7
itsnuwan commentedon Aug 30, 2017
This issue got fixed in java-client-5.0.1.jar