Skip to content

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

Description

@iriszhang1986

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

  1. derunewige commented on Jan 3, 2017

    @derunewige

    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 ?

  2. TikhomirovSergey commented on Jan 3, 2017

    @TikhomirovSergey
    Contributor

    @derunewige
    @iriszhang1986
    Guys, could you invoke the

    driver.getSessionDetails()

    and show the result map here?

  3. TikhomirovSergey commented on Jan 3, 2017

    @TikhomirovSergey
    Contributor

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

  4. derunewige commented on Jan 3, 2017

    @derunewige

    At which place in the code?

  5. saikrishna321 commented on Jan 3, 2017

    @saikrishna321
    Member

    @derunewige

    AppiumDriver<IOSElement> driver  = new IOSDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
    driver.getSessionDetails();
    
  6. derunewige commented on Jan 3, 2017

    @derunewige

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

  7. TikhomirovSergey commented on Jan 3, 2017

    @TikhomirovSergey
    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?

  8. saikrishna321 commented on Jan 3, 2017

    @saikrishna321
    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

  9. SrinivasanTarget commented on Jan 3, 2017

    @SrinivasanTarget
    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.

  10. SrinivasanTarget commented on Jan 3, 2017

    @SrinivasanTarget
    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.

  11. saikrishna321 commented on Jan 3, 2017

    @saikrishna321
    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"}}

  12. SrinivasanTarget commented on Jan 3, 2017

    @SrinivasanTarget
    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.

  13. 1 remaining item

  14. derunewige commented on Jan 4, 2017

    @derunewige

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

  15. derunewige commented on Jan 4, 2017

    @derunewige

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

  16. SrinivasanTarget commented on Jan 4, 2017

    @SrinivasanTarget
    Member

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

  17. derunewige commented on Jan 4, 2017

    @derunewige

    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
    
  18. saikrishna321 commented on Jan 4, 2017

    @saikrishna321
    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

  19. SrinivasanTarget commented on Jan 4, 2017

    @SrinivasanTarget
    Member

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

  20. TikhomirovSergey commented on Jan 4, 2017

    @TikhomirovSergey
    Contributor

    @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.

  21. SrinivasanTarget commented on Jan 4, 2017

    @SrinivasanTarget
    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.

  22. saikrishna321 commented on Jan 4, 2017

    @saikrishna321
    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 ?

  23. SrinivasanTarget commented on Jan 4, 2017

    @SrinivasanTarget
    Member
  24. added a commit that references this issue on Jan 20, 2017
  25. fionazj commented on Jun 5, 2017

    @fionazj

    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

  26. itsnuwan commented on Aug 30, 2017

    @itsnuwan

    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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions