Java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String

Here is my environment: Mavericks OS, Appium 1.3.1, java-client 2.0.0, XCode6.1, iPhone5s, iOS8.1

Here are my codes:
int count = 0;
while (elements(IOS_OBJECT_TYPE.UIATabBar).size() == 0 && count < 3) {
for (String dismisable : dismissables) {
List buttons = elements(By.name(dismisable));
if (buttons.size() > 0) {
System.out.println(buttons.get(0).getText() + ", enabled = " + buttons.get(0).isEnabled() +
", displayed= " + buttons.get(0).isDisplayed());
if (buttons.get(0).isEnabled() == true && buttons.get(0).isDisplayed() == true) {
buttons.get(0).click();
wait(By.className(“UIAButton”));
}
}
}
count++;
}
For some reason, getText() is getting a Long object back and couldn’t cast it into the String, thus it threw this error. Does anyone have any insight on this? What attribute of the GUI object that getText() is grabbing the information from. Could this be an Appium bug?

snippet of the log on the Console

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
at org.openqa.selenium.remote.RemoteWebElement.getText(RemoteWebElement.java:153)
at com.livenation.mobile.ios.page.TabBar.showTabBar(TabBar.java:43)
at com.livenation.mobile.ios.page.TabBar.getTabBar(TabBar.java:57)
at com.livenation.mobile.ios.page.TabBar.clickMore(TabBar.java:82)
at com.livenation.mobile.ios.steps.SignOutSteps.navigateToAccount(SignOutSteps.java:32)
at ✽.And I navigate to the Account page(account/SignInTests.feature:37)

:testFeatures FAILED

FAILURE: Build failed with an exception.

snippet from the Appium log:

2014-11-14 23:00:31:597 - info: [debug] e[32m[INST] 2014-11-14 23:00:32 +0000 Debug: Got new command 132 from instruments: au.getElementByType(‘UIAButton’)e[39m
2014-11-14 23:00:31:610 - info: [debug] e[32m[INST] 2014-11-14 23:00:32 +0000 Debug: evaluating au.getElementByType(‘UIAButton’)e[39m
2014-11-14 23:00:32:029 - info: [debug] e[32m[INST] 2014-11-14 23:00:33 +0000 Debug: evaluation finishede[39m
2014-11-14 23:00:32:042 - info: [debug] e[32m[INST] 2014-11-14 23:00:33 +0000 Debug: Lookup returned [object UIAButton] with the name “Cancel” (id: 181).e[39m
2014-11-14 23:00:32:055 - info: [debug] e[32m[INST] 2014-11-14 23:00:33 +0000 Debug: responding with:e[39m
2014-11-14 23:00:32:067 - info: [debug] e[32m[INST] 2014-11-14 23:00:33 +0000 Debug: Running system command #133: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:{“ELEMENT”:“181”}}…e[39m
2014-11-14 23:00:32:073 - info: [debug] Socket data received (40 bytes)
2014-11-14 23:00:32:073 - info: [debug] Socket data being routed.
2014-11-14 23:00:32:074 - info: [debug] Got result from instruments: {“status”:0,“value”:{“ELEMENT”:“181”}}
2014-11-14 23:00:32:074 - info: [debug] Responding to client with success: {“status”:0,“value”:{“ELEMENT”:“181”},“sessionId”:“92193bcf-869e-4353-beeb-040108598db8”}
2014-11-14 23:00:32:074 - info: e[37m<-- POST /wd/hub/session/92193bcf-869e-4353-beeb-040108598db8/element e[39me[32m200e[39me[90m 1038.613 ms - 89e[39m e[90m{“status”:0,“value”:{“ELEMENT”:“181”},“sessionId”:“92193bcf-869e-4353-beeb-040108598db8”}e[39m
2014-11-14 23:00:32:077 - info: e[37m–>e[39m e[37mGETe[39m e[37m/wd/hub/session/92193bcf-869e-4353-beeb-040108598db8/element/181/displayede[39m e[90m{}e[39m
2014-11-14 23:00:32:077 - info: [debug] Pushing command to appium work queue: “au.getElement(‘181’).isDisplayed()”
2014-11-14 23:00:32:077 - info: [debug] Sending command to instruments: au.getElement(‘181’).isDisplayed()
2014-11-14 23:00:33:124 - info: [debug] e[32m[INST] 2014-11-14 23:00:34 +0000 Debug: Got new command 133 from instruments: au.getElement(‘181’).isDisplayed()e[39m
2014-11-14 23:00:33:138 - info: [debug] e[32m[INST] 2014-11-14 23:00:34 +0000 Debug: evaluating au.getElement(‘181’).isDisplayed()e[39m
2014-11-14 23:00:33:150 - info: [debug] e[32m[INST] 2014-11-14 23:00:34 +0000 Debug: evaluation finishede[39m
2014-11-14 23:00:33:157 - info: [debug] Socket data received (28 bytes)
2014-11-14 23:00:33:157 - info: [debug] Socket data being routed.
2014-11-14 23:00:33:158 - info: [debug] Got result from instruments: {“status”:0,“value”:false}
2014-11-14 23:00:33:158 - info: [debug] Responding to client with success: {“status”:0,“value”:false,“sessionId”:“92193bcf-869e-4353-beeb-040108598db8”}
2014-11-14 23:00:33:158 - info: e[37m<-- GET /wd/hub/session/92193bcf-869e-4353-beeb-040108598db8/element/181/displayed e[39me[32m200e[39me[90m 1080.979 ms - 77e[39m e[90m{“status”:0,“value”:false,“sessionId”:“92193bcf-869e-4353-beeb-040108598db8”}e[39m
2014-11-14 23:00:33:162 - info: [debug] e[32m[INST] 2014-11-14 23:00:34 +0000 Debug: responding with:e[39m
2014-11-14 23:00:33:174 - info: [debug] e[32m[INST] 2014-11-14 23:00:34 +0000 Debug: Running system command #134: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:false}…e[39m
2014-11-14 23:00:34:007 - info: e[37m–>e[39m e[37mGETe[39m e[37m/wd/hub/session/92193bcf-869e-4353-beeb-040108598db8/screenshote[39m e[90m{}e[39m
2014-11-14 23:00:34:008 - info: [debug] Pushing command to appium work queue: “au.getScreenOrientation()”
2014-11-14 23:00:34:008 - info: [debug] Sending command to instruments: au.getScreenOrientation()
2014-11-14 23:00:34:219 - info: [debug] e[32m[INST] 2014-11-14 23:00:35 +0000 Debug: Got new command 134 from instruments: au.getScreenOrientation()e[39m
2014-11-14 23:00:34:232 - info: [debug] e[32m[INST] 2014-11-14 23:00:35 +0000 Debug: evaluating au.getScreenOrientation()e[39m
2014-11-14 23:00:34:244 - info: [debug] e[32m[INST] 2014-11-14 23:00:35 +0000 Debug: evaluation finishede[39m
2014-11-14 23:00:34:256 - info: [debug] e[32m[INST] 2014-11-14 23:00:35 +0000 Debug: responding with:e[39m
2014-11-14 23:00:34:260 - info: [debug] Socket data received (33 bytes)

I had found the same issue and I wanted to report a bug 3 weeks ago. Unfortunately code was lost and I hadn’t much time for investigation of the problem. :frowning:

It depends somehow on element which you want to interact with.
Some invocations:

element.getText();

return String value. Some invocations of getText() receive 0 from the launched Appium server before they return the result. 0 can not be cast to String(!!!). It is the root cause and I think that it is the server-side problem.

But I couldn’t find the pattern which helps to divide “good” elements from “bad” (I had seen only one “bad” element). Please report a bug here.

Hi Sergey,

I have categorized this as “Issues/Bugs”, so what do you mean by “Please report a bug here.” as your last sentence. Am I missing something? Please let me know.

Hi Sergey,
Please ignore my comment. I have submitted a bug from your provided link. Thanks!

It is ok! I added my own comment.

So, the actual issue is