Java-client: java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement

Created on 28 Nov 2017  Â·  14Comments  Â·  Source: appium/java-client

Issue Description along with Code:

protected WindowsDriver driver;

java.lang.ClassCastException Issue if directly access the method like below:
System.out.print("Title Check: "+driver.findElementByAccessibilityId("Title).getText());

WorkAround: No java.lang.ClassCastException Issue if cast to the WebElement like below.
WebElement title = driver.findElementByAccessibilityId("Title");
getPrintHelper().print("Check the App Title: "+title.getText());

Environment:
Maven POM File:
5.0.4
3.6.0
6.11


io.appium
java-client
${appium.version}


org.seleniumhq.selenium
selenium-java
${selenium.version}


org.testng
testng
${testng.version}

Appium server version or git revision: WinAppDriver V1.0 release (File Version 1.0.1710.17001)

Desktop OS/version used to run Appium if necessary: Windows 10
Mobile platform/version under test: Windows 10 App

Note: Looks like same/similar issue as following:
https://github.com/Microsoft/WinAppDriver/issues/286

Exception stacktraces:
https://gist.github.com/aeroclee/b1d3bba03c3188d575b251b557c13cec

Needs investigation bug testing

Most helpful comment

Sergey,

Sorry if you saw the post previous to this a few minutes ago (I deleted it). It was for the wrong issue.

Unfortunately, I cannot share my code as it belongs to a client.

I finally did get my code to work however. https://github.com/notifications/beacon/AAjPaKyLqYXYkMMtN63IAbq720pu5p_kks5s8cGLgaJpZM4Qsckg.gif The problem is casting to a subclass (or better put, trying to cast a Superclass to a Subclass).

WindwosElement is derived from MobileElement, which is derived from RemoteWebElement.

If you write code like this:

WindowsElement title = driver.findElementByAccessibilityId("Title");

You are trying to cast a RemoteWebElement (which the right side returns, a Superclass) to one of its subclasses WindowsElement.

While the compiler trust you to do this, at runtime, it is caught, and the Exception we are discussing is thrown.

The workaround, appears to be the right way to handle it, though you would probably have access to more functionality if you utilize RemoteWebElement as I have done, as RemoteWebElement is a Class that Implements the WebElement interface.

As far as I can tell, this is the way the Java Client code has been architected (Functions As Designed).

The test cases for the Java Client never encounter this issue, as they never store a returned WebElement and utilize it, according to my sparse review.

So, when I declare my WindowsDriver, I do so like this WindowsDriver instead of WindowsDriver as instructed.

One last interesting note
.driver.findElementsByAccessiblityId (note the plural findElements), returns a List and you must declare your variable this way. However, as you iterate over that list and inspect the list for what you are looking for, you must use a RemoteWebElement variable, and essentially down cast it.

I hope this is helpful.

Thanks.

David

All 14 comments

The workaround may work for reading/retrieving text, but it does not appear to work for writing/sending text (sendKeys).

Please make this a higher priority, as by my experience, it does not appear that there is a workaround for all situations.

Note: I am using the latest releases of all libraries noted above, except no TestNG. This includes java-client.

It seems we have not covered Winddows with tests. It is our fault I think. It is going to be fixed at the next BETA version.

@aeroclee Some questions/asking to make it clear

Are you automating native or web/hybrid application? may be desktop app?
Could you provide extanded sample to reproduce the issue and to check fixes?

Sergey,

Sorry if you saw the post previous to this a few minutes ago (I deleted it). It was for the wrong issue.

Unfortunately, I cannot share my code as it belongs to a client.

I finally did get my code to work however. https://github.com/notifications/beacon/AAjPaKyLqYXYkMMtN63IAbq720pu5p_kks5s8cGLgaJpZM4Qsckg.gif The problem is casting to a subclass (or better put, trying to cast a Superclass to a Subclass).

WindwosElement is derived from MobileElement, which is derived from RemoteWebElement.

If you write code like this:

WindowsElement title = driver.findElementByAccessibilityId("Title");

You are trying to cast a RemoteWebElement (which the right side returns, a Superclass) to one of its subclasses WindowsElement.

While the compiler trust you to do this, at runtime, it is caught, and the Exception we are discussing is thrown.

The workaround, appears to be the right way to handle it, though you would probably have access to more functionality if you utilize RemoteWebElement as I have done, as RemoteWebElement is a Class that Implements the WebElement interface.

As far as I can tell, this is the way the Java Client code has been architected (Functions As Designed).

The test cases for the Java Client never encounter this issue, as they never store a returned WebElement and utilize it, according to my sparse review.

So, when I declare my WindowsDriver, I do so like this WindowsDriver instead of WindowsDriver as instructed.

One last interesting note
.driver.findElementsByAccessiblityId (note the plural findElements), returns a List and you must declare your variable this way. However, as you iterate over that list and inspect the list for what you are looking for, you must use a RemoteWebElement variable, and essentially down cast it.

I hope this is helpful.

Thanks.

David

Can someone please help me. I am new to Appium, I have an Android App that I am trying to Automate.

My App that I am automating is a combination of Native and Web App. With the code that I have written I am able to open the App. Using UI Inspector I am able to locate elements as well. After running the code App opens up but It’s unable to take user name and password

Here’s my code with Appium logs and Selenium Webdriver Error:

package amazon;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

//import org.openqa.selenium.By;
//import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class AcceleratorLogin {
AndroidDriver driver;

public void invokeLogin() {

File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/Apps/AcceleratorApp/");
File app = new File(appDir, "Accelerator_3.0Test_TimestampFix.apk");

DesiredCapabilities capabilities = new DesiredCapabilities();
//capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Galaxt Tab E");
capabilities.setCapability("platformVersion", "7.1.1");

capabilities.setCapability("platformName", "Android");
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.navistar.writeup");
capabilities.setCapability("appActivity", "com.navistar.writeup.AcceleratorActivity");
try {

    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

}
Selenium Error:
java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement
at amazon.AcceleratorLogin.userLogin(AcceleratorLogin.java:45)
at amazon.AcceleratorLogin.main(AcceleratorLogin.java:57)

Appium Logs:

[Appium] Appium REST http interface listener started on 127.0.0.1:4723
[HTTP] --> POST /wd/hub/session {“desiredCapabilities”:{“app”:“C:\Users\u01n233\eclipse-workspace\AppiumTestProject\Apps\AcceleratorApp\Accelerator_3.0Test_TimestampFix.apk”,“appActivity”:“com.navistar.writeup.AcceleratorActivity”,“appPackage”:“com.navistar.writeup”,“automationName”:“Appium”,“deviceName”:“Galaxt Tab E”,“platformName”:“Android”,“platformVersion”:“7.1.1”},“capabilities”:{“desiredCapabilities”:{“app”:“C:\Users\u01n233\eclipse-workspace\AppiumTestProject\Apps\AcceleratorApp\Accelerator_3.0Test_TimestampFix.apk”,“appActivity”:“com.navistar.writeup.AcceleratorActivity”,“appPackage”:“com.navistar.writeup”,“automationName”:“Appium”,“deviceName”:“Galaxt Tab E”,“platformName”:“Android”,“platformVersion”:“7.1.1”},“firstMatch”:[{“platformName”:“android”}]}}
[MJSONWP] Calling AppiumDriver.createSession() with args: [{“app”:“C:\Users\u01n233\eclipse-workspace\AppiumTestProject\Apps\AcceleratorApp\Accelerator_3.0Test_TimestampFix.apk”,“appActivity”:“com.navistar.writeup.AcceleratorActivity”,“appPackage”:“com.navistar.writeup”,“automationName”:“Appium”,“deviceName”:“Galaxt Tab E”,“platformName”:“Android”,“platformVersion”:“7.1.1”},null,{“desiredCapabilities”:{“app”:“C:\Users\u01n233\eclipse-workspace\AppiumTestProject\Apps\AcceleratorApp\Accelerator_3.0Test_TimestampFix.apk”,“appActivity”:“com.navistar.writeup.AcceleratorActivity”,“appPackage”:“com.navistar.writeup”,“automationName”:“Appium”,“deviceName”:“Galaxt Tab E”,“platformName”:“Android”,“platformVersion”:“7.1.1”},“firstMatch”:[{“platformName”:“android”}]}]
[BaseDriver] Event ‘newSessionRequested’ logged at 1519320234628 (11:23:54 GMT-0600 (Central Standard Time))
[Appium] Merged W3C capabilities {“desiredCapabilities”:{“app”:“C:\Users\u01n2
 into desiredCapabilities object {“app”:“C:\Users\u01n233\eclipse-workspace\

[Appium] Creating new AndroidDriver (v1.37.0) session
[Appium] Capabilities:
[Appium] app: C:\Users\u01n233\eclipse-workspace\AppiumTestProject\Apps\AcceleratorApp\Accelerator_3.0Test_TimestampFix.apk
[Appium] appActivity: com.navistar.writeup.AcceleratorActivity
[Appium] appPackage: com.navistar.writeup
[Appium] automationName: Appium
[Appium] deviceName: Galaxt Tab E
[Appium] platformName: android
[Appium] platformVersion: 7.1.1
[BaseDriver] Session created with session id: 1ab1bd8e-1899-466c-b9f0-2aeda35eab3f
[AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_151
[ADB] Checking whether adb is present
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[AndroidDriver] Looking for a device with Android ‘7.1.1’
[ADB] Setting device id to fc591f301b82ddb5
[ADB] Getting device platform version
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: [”-P”,5037,"-s",“fc591f301b82ddb5”,“shell”,“getprop”,“ro.build.version.release”]
[ADB] Current device property ‘ro.build.version.release’: 7.1.1
[AndroidDriver] Using device: fc591f301b82ddb5
[ADB] Checking whether adb is present
[ADB] Setting device id to fc591f301b82ddb5
[BaseDriver] Using local app ‘C:\Users\u01n233\eclipse-workspace\AppiumTestProject\Apps\AcceleratorApp\Accelerator_3.0Test_TimestampFix.apk’
[AndroidDriver] Checking whether app is actually present
[AndroidDriver] Starting Android session
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“wait-for-device”]
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“echo”,“ping”]
[AndroidDriver] setDeviceLanguageCountry requires language or country.
[AndroidDriver] Got language: ‘undefined’ and country: ‘undefined’
[Logcat] Starting logcat capture
[AndroidDriver] Pushing settings apk to device

[ADB] Getting install status for io.appium.settings
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“pm”,“list”,“packages”,“io.appium.settings”]
[ADB] App is installed
[ADB] Getting package info for io.appium.settings
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“dumpsys”,“package”,“io.appium.settings”]
[ADB] Checking whether aapt is present
[ADB] The installed ‘io.appium.settings’ package does not require upgrade (5 >= 5)
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“getprop”,“ro.build.version.sdk”]
[ADB] Current device property ‘ro.build.version.sdk’: 25
[ADB] Device API level: 25
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“dumpsys”,“package”,“io.appium.settings”]
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“pm”,“dump”,“io.appium.settings”]
[ADB] Got the following command chunks to execute: pm,grant,io.appium.settings,android.permission.WRITE_SETTINGS,;,pm,grant,io.appium.settings,android.permission.ACCESS_MOCK_LOCATION,;
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“pm”,“grant”,“io.appium.settings”,“android.permission.WRITE_SETTINGS”,";",“pm”,“grant”,“io.appium.settings”,“android.permission.ACCESS_MOCK_LOCATION”,";"]
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“pm”,“grant”,“io.appium.settings”,“android.permission.WRITE_SETTINGS”,";",“pm”,“grant”,“io.appium.settings”,“android.permission.ACCESS_MOCK_LOCATION”,";"]
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“ps”]
[ADB] Device API level: 25
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“am”,“start”,"-W","-n",“io.appium.settings/.Settings”,"-a",“android.intent.action.MAIN”,"-c",“android.intent.category.LAUNCHER”,"-f",“0x10200000”]
[ADB] Device API level: 25
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“appops”,“set”,“io.appium.settings”,“android:mock_location”,“allow”]
[AndroidDriver] Pushing unlock helper app to device

[ADB] Getting install status for io.appium.unlock
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“pm”,“list”,“packages”,“io.appium.unlock”]
[ADB] App is installed
[ADB] Getting package info for io.appium.unlock
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“dumpsys”,“package”,“io.appium.unlock”]
[ADB] Checking whether aapt is present
[ADB] The installed ‘io.appium.unlock’ package does not require upgrade (2 >= 2)
[ADB] Getting device platform version
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“getprop”,“ro.build.version.release”]
[ADB] Current device property ‘ro.build.version.release’: 7.1.1
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“wm”,“size”]
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“getprop”,“ro.product.model”]
[ADB] Current device property ‘ro.product.model’: SM-T560NU
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“getprop”,“ro.product.manufacturer”]
[ADB] Current device property ‘ro.product.manufacturer’: samsung
[AndroidDriver] Remote apk path is /data/local/tmp/1ae3bbafefcb152e97400c52646c1329.apk
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“ls”,"/data/local/tmp/1ae3bbafefcb152e97400c52646c1329.apk"]
[AndroidDriver] Checking if app is installed
[ADB] Getting install status for com.navistar.writeup
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“pm”,“list”,“packages”,“com.navistar.writeup”]
[ADB] App is installed
[AndroidDriver] Apk is already on remote and installed, resetting
[AndroidDriver] Running fast reset (stop and clear)
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“am”,“force-stop”,“com.navistar.writeup”]
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“pm”,“clear”,“com.navistar.writeup”]
[AndroidDriver] Extracting strings from apk C:\Users\u01n233\eclipse-workspace\AppiumTestProject\Apps\AcceleratorApp\Accelerator_3.0Test_TimestampFix.apk undefined C:\Users\u01n233\AppData\Local\Temp\com.navistar.writeup
[ADB] Extracting strings for language: default
[ADB] Device API level: 25
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“getprop”,“persist.sys.locale”]
[ADB] Current device property ‘persist.sys.locale’: en-US
[ADB] No strings.xml for language ‘en’, getting default strings.xml
[ADB] Reading strings from converted strings.json
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“push”,“C:\Users\u01n233\AppData\Local\Temp\com.navistar.writeup\strings.json”,"/data/local/tmp"]
[AndroidBootstrap] Watching for bootstrap disconnect
[ADB] Forwarding system: 4724 to device: 4724
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“forward”,“tcp:4724”,“tcp:4724”]
[UiAutomator] Starting UiAutomator
[UiAutomator] Moving to state ‘starting’
[UiAutomator] Parsing uiautomator jar
[UiAutomator] Found jar name: ‘AppiumBootstrap.jar’
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“push”,“C:\Users\u01n233\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-android-bootstrap\bootstrap\bin\AppiumBootstrap.jar”,"/data/local/tmp/"]
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“ps”]
[ADB] Attempting to kill process 18784
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“kill”,"-0",18784]
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“kill”,18784]
[UiAutomator] UiAutomator exited unexpectedly with code 4294967183, signal null
[UiAutomator] Moving to state ‘stopped’
[AndroidDriver] Shutting down Android driver
[Appium] Closing session, cause was ‘UiAUtomator shut down unexpectedly’
[Appium] Removing session 585a649e-f01a-4d9f-8298-896f473fb0b6 from our master session list
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“am”,“force-stop”,“com.navistar.writeup”]
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“kill”,18784]
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“kill”,18784]
[UiAutomator] Starting UIAutomator
[ADB] Creating ADB subprocess with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“uiautomator”,“runtest”,“AppiumBootstrap.jar”,"-c",“io.appium.android.bootstrap.Bootstrap”,"-e",“pkg”,“com.navistar.writeup”,"-e",“disableAndroidWatchers”,false,"-e",“acceptSslCerts”,false]
[ADB] Pressing the HOME button
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“input”,“keyevent”,3]
[UiAutomator] Moving to state ‘online’
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] json loading complete.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] Android bootstrap socket is now connected
[ADB] Getting connected devices

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“dumpsys”,“window”]
[AndroidBootstrap] Cannot shut down Android bootstrap; it has already shut down
[Logcat] Stopping logcat capture
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“am”,“force-stop”,“io.appium.unlock”]
[AndroidDriver] Screen already unlocked, doing nothing
[ADB] Device API level: 25
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“am”,“start”,"-W","-n",“com.navistar.writeup/com.navistar.writeup.AcceleratorActivity”,"-S"]
[AndroidDriver] Not cleaning generated files. Add clearSystemFiles capability if wanted.
[Appium] New AndroidDriver session created successfully, session 1ab1bd8e-1899-466c-b9f0-2aeda35eab3f added to master session list
[BaseDriver] Event ‘newSessionStarted’ logged at 1519320276629 (11:24:36 GMT-0600 (Central Standard Time))
[MJSONWP] Responding to client with driver.createSession() result: {“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“app”:“C:\Users\u01n233\eclipse-workspace\AppiumTestProject\Apps\AcceleratorApp\Accelerator_3.0Test_TimestampFix.apk”,“appActivity”:“com.navistar.writeup.AcceleratorActivity”,“appPackage”:“com.navistar.writeup”,“automationName”:“Appium”,“deviceName”:“Galaxt Tab E”,“platformName”:“android”,“platformVersion”:“7.1.1”},“app”:“C:\Users\u01n233\eclipse-workspace\AppiumTestProject\Apps\AcceleratorApp\Accelerator_3.0Test_TimestampFix.apk”,“appActivity”:“com.navistar.writeup.AcceleratorActivity”,“appPackage”:“com.navistar.writeup”,“automationName”:“Appium”,“deviceName”:“fc591f301b82ddb5”,“platformName”:“android”,“platformVersion”:“7.1.1”,“deviceUDID”:“fc591f301b82ddb5”,“deviceScreenSize”:“800x1280”,“deviceModel”:“SM-T560NU”,“deviceManufacturer”:“samsung”}
[HTTP] <-- POST /wd/hub/session 200 41999 ms - 1048
[HTTP] --> POST /wd/hub/session/1ab1bd8e-1899-466c-b9f0-2aeda35eab3f/element {“using”:“id”,“value”:“username”}
[MJSONWP] Calling AppiumDriver.findElement() with args: [“id”,“username”,“1ab1bd8e-1899-466c-b9f0-2aeda35eab3f”]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“id”,“selector”:“username”,“context”:"",“multiple”:false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“id”,“selector”:“username”,“context”:"",“multiple”:false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘username’ using ‘ID’ with the contextId: ‘’ multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.navistar.writeup:id/username]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=android:id/username]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=username]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:{“ELEMENT”:“1”}}
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.findElement() result: {“ELEMENT”:“1”}
[HTTP] <-- POST /wd/hub/session/1ab1bd8e-1899-466c-b9f0-2aeda35eab3f/element 200 30459 ms - 87
[BaseDriver] Shutting down because we waited 60 seconds for a command
[AndroidDriver] Shutting down Android driver
[Appium] Closing session, cause was ‘New Command Timeout of 60 seconds expired. Try customizing the timeout using the ‘newCommandTimeout’ desired capability’
[Appium] Removing session 1ab1bd8e-1899-466c-b9f0-2aeda35eab3f from our master session list
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“am”,“force-stop”,“com.navistar.writeup”]
[ADB] Pressing the HOME button
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“input”,“keyevent”,3]
[AndroidBootstrap] Sending command to android: {“cmd”:“shutdown”}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“shutdown”}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:“OK, shutting down”}
[AndroidBootstrap] Received command result from bootstrap
[UiAutomator] Shutting down UiAutomator
[UiAutomator] Moving to state ‘stopping’
[UiAutomator] UiAutomator shut down normally
[UiAutomator] Moving to state ‘stopped’
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“ps”]
[ADB] No uiautomator process found to kill, continuing

[UiAutomator] Moving to state ‘stopped’
[Logcat] Stopping logcat capture
[ADB] Getting connected devices

[ADB] 1 device(s) connected
[ADB] Running ‘C:\Android\android-sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“fc591f301b82ddb5”,“shell”,“am”,“force-stop”,“io.appium.unlock”]
[AndroidDriver] Not cleaning generated files. Add clearSystemFiles capability if wanted.
Appium server stopped successfully

Yes
im getting below issue

How to resolve the issue

java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement
at com.zenq.demo.AppTest.main(AppTest.java:67)
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:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:571)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
at org.testng.TestNG.runSuites(TestNG.java:1028)
at org.testng.TestNG.run(TestNG.java:996)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)

//Code is Here

@Test
public void main() {

        try
        {

            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("device", "Android");
            capabilities.setCapability("deviceName", "Nexus 5 ");
            capabilities.setCapability("udid", "077c35ee0ade546b");

            capabilities.setCapability("platformName", "Android");
            // You need to have this sdk installed for Appium to work
            capabilities.setCapability("platformVersion", "5.1.1");
            capabilities.setCapability("appPackage", "net.one97.paytm");
            capabilities.setCapability("appActivity", "net.one97.paytm.landingpage.activity.AJRMainActivity");
            //capabilities.setCapability("apkFile", apkFile.getAbsolutePath());
            capabilities.setCapability("autoGrantPermissions","true");

            URL url=new URL("http://0.0.0.0:4723/wd/hub");

           // RemoteWebDriver driver= new RemoteWebDriver(url, capabilities);

            AndroidDriver<MobileElement> androidDriver=new AndroidDriver<MobileElement>(url,capabilities);
            //RemoteWebDriver driver=androidDriver;

            System.out.println(androidDriver.toString());

    //Here im getting cast exception    
androidDriver.findElement(By.id("net.one97.paytm:id/btn_language_continue_button")).click();

        }
        catch(Exception e)
        {
e.printStackTrace();
        }
    }
}

Even I'm facing the same issue i.e io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen

capabilities.setCapability(MobileCapabilityType.VERSION, Config.get("MobileCapabilityType.VERSION"));
capabilities.setCapability("appPackage", Config.get("appPackage"));
capabilities.setCapability("appActivity", Config.get("appActivity"));
capabilities.setCapability(MobileCapabilityType.APP, Config.get("apkPath"));
URL url = new URL("http://127.0.0.1:4723/wd/hub");
mdriver = new AndroidDriver(url, capabilities);

public static void singleTap(AppiumDriver mdriver, By locator) {
try {
TouchActions action = new TouchActions(mdriver);
action.singleTap(mdriver.findElement(locator));
action.perform();
Assert.assertTrue(true);
} catch (Exception e) {
Assert.fail("The element : " + locator + " is not visibile/not enabled - '"
+ "' and the error message is " + e.getMessage());
}
}

Mobile.singleTap(mdriver, By.id("io.selendroid.testapp:id/buttonTest"));

Error : java.lang.AssertionError: The element : By.id: io.selendroid.testapp:id/buttonTest is not visibile/not enabled and the error message is io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen.

Please help me.

Download and add the below jar file into your Project @Vidya Sagar Pogiri
selenium-api/selenium-api-2.26.0.jar.zip( 117 k)

I have this issue in Windows/C# when finding by id. Very annoying

I have the same issue (Invalid Cast Exception) when using C# on Windows to automate an iOS app running in a simulator on a Mac. The exception happens when running the following code after declaring the IOSDriver< IOSElement >: IWebElement result = this.Driver.FindElement(strategy);. "this.Driver" is an IWebDriver reference to the IOSDriver < IOSElement >. The Workaround as discussed above is to declare the driver this way: IOSDriver < RemoteWebElement >. But, I'm sure I'm going to run into issues on the FindElements code. Our automation code works across iOS, Windows, and Android via fairly generic automation tests written in C#. I hope things like this will be fixed!

Dear Sir:
I also have the same problem.
I can not use AndroidDriver.
I can only use RemoteWebDriver.
Code:
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class ScorllBar {

private static RemoteWebDriver driver =null;
private static AndroidDriver androidDriver=null;

    public static void main(String[] args) throws MalformedURLException, Exception  {
    // TODO Auto-generated method stub
    DesiredCapabilities cap =   new DesiredCapabilities();
    cap.setCapability("platformName", "Android");
    cap.setCapability("platformVersion", 5); 
    cap.setCapability("deviceName", "Android Emulator");
    cap.setCapability("automationName", "Appium");  
    cap.setCapability("appPackage", "tw.com.wgh3h");  
    cap.setCapability("appActivity", "tw.com.demo1.MyMainPage");  
    //RemoteWebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
    AndroidDriver androidDriver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);
    driver = androidDriver;
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

ErrorMessage:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/websocket/DeploymentException
at io.appium.java_client.android.ListensToLogcatMessages.(ListensToLogcatMessages.java:34)
at ScorllBar.main(ScorllBar.java:32)
Caused by: java.lang.ClassNotFoundException: javax.websocket.DeploymentException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Test environment:
Java Client:java-client-6.0.0
Appium:1.8.1
Eclipse:Oxygen.3a Release (4.7.3a)

how to switch native to webview am not able to do in iOS app, getting below error whenever i tried using above code
@ronjonesjr @dpgraham @sbonebrake @mykola-mokhnach @imurchie please help


AppiumDriver
at io.appium.java_client.AppiumDriver.getContextHandles(AppiumDriver.java:227)
at ZDebugTests.iOSTest.main(iOSTest.java:28)
Caused by: java.lang.ClassCastException: com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to java.util.List
at io.appium.java_client.AppiumDriver.getContextHandlesï»ż

same issue with

TouchActions action = new TouchActions(driver); action.scroll(fwutils.CheckElement(driver, path_video_label, "xpath"), 100, 100); action.perform();

fwutils is:
`public MobileElement CheckElement(AppiumDriver driver, String path, String option) throws Exception
{
MobileElement element = null;

    switch (option)
    {
        case "xpath":
            element = (MobileElement) driver.findElementByXPath(path);
            break;

        case "id":
            element = (MobileElement) driver.findElementById(path);
            break;

        case "access_id":
            element = (MobileElement) driver.findElementByAccessibilityId(path);
            break;
    }

    if (element == null)
    {
        throw new Exception(path + " not found");
    }

    return (element);
}`

getting:
Exception: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreenjava.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen
is that beta version really coming? a year has passed

Hey, I'm having the same issues with my java client binding verison 7.0.0 with using appium. I get the same "cannot be cast" error and I'm not able to send any text to a field in my desktop application for my automation. Any updates on this issue?

Was this page helpful?
0 / 5 - 0 ratings