Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
iriszhang1986 opened this issue Jan 3, 2017 · 25 comments

Comments

@iriszhang1986
Copy link

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}

@derunewige
Copy link

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.

AppiumDriver<IOSElement> driver  = new IOSDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
List<IOSElement> allTravelActions = driver.findElementsById("travelActions.title");
allTravelActions.get(0).click();

The last line with .click() leads to the following error:

org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.ios.IOSElement
And also in a for each loop this error occurs

ArrayList<IOSElement> top10list = driver.findElementsById("stationSearch.station.name");
for (IOSElement item : top10list){
}

Debugging shows me, that "driver.findElementsByAccessibilityId" returns a List of RemoteWebElements (screenshot01 + 02)
screenshot01
screenshot02

Why do I get RemoteWebElements from my AppiumDriver ?

@TikhomirovSergey
Copy link
Contributor

@derunewige
@iriszhang1986
Guys, could you invoke the

driver.getSessionDetails()

and show the result map here?

@TikhomirovSergey
Copy link
Contributor

It is defenetely the bug but now I'm trying to get my local Mac machine fixed

@derunewige
Copy link

At which place in the code?

@saikrishna321
Copy link
Member

saikrishna321 commented Jan 3, 2017

@derunewige

AppiumDriver<IOSElement> driver  = new IOSDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
driver.getSessionDetails();

@derunewige
Copy link

derunewige commented Jan 3, 2017

@TikhomirovSergey

15:20:50.020 [main] DEBUG utils.AppiumDriverBuilder - Before printing session details
15:20:50.191 [main] DEBUG utils.AppiumDriverBuilder - {capabilities={browserName=XXX, sdkVersion=10.0, CFBundleIdentifier=xx.xxxx.XXX, device=iphone}, sessionId=6128EC79-3030-42D3-B661-232581D8D9C6}
15:20:50.380 [main] DEBUG utils.AppiumDriverBuilder - After printing session details

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
Copy link
Contributor

@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
Copy link
Member

@TikhomirovSergey

The first problem is that we didn't expect that session can't contain any information about platform/automation

All the details are received from server including the automation and platform and lot more. Sample response

"status": 0,
  "value": {
    "platform": "LINUX",
    "webStorageEnabled": false,
    "takesScreenshot": true,
    "javascriptEnabled": true,
    "databaseEnabled": false,
    "networkConnectionEnabled": true,
    "locationContextEnabled": false,
    "warnings": {

    },
    "desired": {
      "app": "\/Users\/saikrisv\/git\/java-client\/java-client\/src\/test\/java\/io\/appium\/java_client\/IntentExample.apk",
      "platformName": "Android",
      "deviceName": "Android Emulator"
    },
    "app": "\/Users\/saikrisv\/git\/java-client\/java-client\/src\/test\/java\/io\/appium\/java_client\/IntentExample.apk",
    "platformName": "Android",
    "deviceName": "192.168.65.101:5555",
    "deviceUDID": "192.168.65.101:5555",
    "platformVersion": "5.0",
    "appPackage": "com.prgguru.android",
    "appWaitPackage": "com.prgguru.android",
    "appActivity": "com.prgguru.android.IntentExampleActivity",
    "appWaitActivity": "com.prgguru.android.IntentExampleActivity"
  },
  "sessionId": "0ac42e16-65c3-40ec-bcf0-fae7d9dd9a4a"
}

let me try on real device

@SrinivasanTarget
Copy link
Member

I see Automation Name or Platform Details is not coming up in session details at times when we run on XCUITMode (Only in XCUITMode) even on simulators.

@SrinivasanTarget
Copy link
Member

@iriszhang1986 @derunewige Please do a run without below capabilities and send us entire server logs.

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);

Between i'm debugging it as well.

@saikrishna321
Copy link
Member

@SrinivasanTarget @TikhomirovSergey with legacy driver i get the below response, which looks fine to me. May be as srini mentioned could be with XCUITest

public void iosSetup() throws MalformedURLException {
        caps.setCapability(MobileCapabilityType.UDID, "xxx");
        caps.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone SE");
        caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.3.2");
        caps.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "xxx");
        caps.setCapability(MobileCapabilityType.APP,"/Users/saikrisv/Downloads/debug.ipa");
        driver = new IOSDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);

    }

{"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
Copy link
Member

Yes it is fine in legacy driver and UIAutomator2 mode but Automation Name is not coming if we didn't specify it explicitly in desired caps and running on iOS10 sims.

@TikhomirovSergey
Copy link
Contributor

@derunewige @SrinivasanTarget @saikrishna321
Ok. I can propose a PR. But there is some server side issue defenetely.

@derunewige
Copy link

Good morning!

here is the server log without these four caps: gist

So it is only:

log.info("AppiumDriverBuilder: creating driver for iOS10 SIM environment");
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/kevinbeschorner/Desktop/OEBB App.app"); 
caps.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "at.oebb.TSMobileTesting");

driver = new IOSDriver<IOSElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
log.debug("Before printing session details");
log.info(driver.getSessionDetails());
log.debug("After printing session details");

Console log:

09:32:00.709 [main] DEBUG utils.AppiumDriverBuilder - Before printing session details
09:32:01.054 [main] DEBUG utils.AppiumDriverBuilder - {capabilities={browserName= , sdkVersion=10.0, CFBundleIdentifier=local.pid.67916, device=iphone}, sessionId=8C0229D6-7A26-4025-B3A1-0F7BCB7F5F98}
09:32:01.055 [main] DEBUG utils.AppiumDriverBuilder - After printing session details

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
Copy link

I did an update from appium 1.6.1-beta to 1.6.3 and now it looks like it is working!

@SrinivasanTarget
Copy link
Member

@derunewige Can you attach the latest logs as well here (1.6.3)?

@derunewige
Copy link

derunewige commented Jan 4, 2017

Yes, of course: gist

Thank you all for your support!

11:15:55.076 [main] DEBUG utils.AppiumDriverBuilder - Before printing session details
11:15:55.275 [main] INFO  utils.AppiumDriverBuilder - {app=/Users/username/Desktop/appname.app, noReset=true, bundleId=xx.xxxx.XXX, CFBundleIdentifier=xx.xxxx.XXX, deviceName=iPhone 7, fullReset=false, sendKeyStrategy=setValue, platformVersion=10.0, automationName=XCuiTest, browserName=app, sdkVersion=10.0, udid=48E841E8-C603-42A0-AD37-AC5DF668F32F, platformName=iOS, device=iphone, autoAcceptAlerts=true}
11:15:55.276 [main] DEBUG utils.AppiumDriverBuilder - After printing session details

@saikrishna321
Copy link
Member

@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
Copy link
Member

Yes @saikrishna321. Session details is a server issue but anyways we need a fix for this which @TikhomirovSergey is working on.

@TikhomirovSergey
Copy link
Contributor

TikhomirovSergey commented 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
Copy link
Member

@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
Copy link
Member

@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
Copy link
Member

SrinivasanTarget commented Jan 4, 2017 via email

@fionazj
Copy link

fionazj commented 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
Copy link

This issue got fixed in java-client-5.0.1.jar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants