1

I have below configurations :

Javaclient : java-client-5.0.2

Selenium : 3.0.1

Java : 144

Appium v1.4.16

This is my code :

package com.metatag.poc;


import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.apache.bcel.generic.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;


public class DesignLayout {

    //private static AndroidDriver driver;
    static AndroidDriver<MobileElement> driver;
    static WebElement ele;


    public static void main(String[] args) throws MalformedURLException, InterruptedException, WebDriverException {

        File classpathRoot = new File(System.getProperty("user.dir"));
        File appDir = new File(classpathRoot, "/Apps/");
        File app = new File(appDir, "MetaTag_V0.0.13_preview.apk");

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
//set capabilities          
        capabilities.setCapability("deviceName", "3G7");
        capabilities.setCapability("platformVersion", "4.4.1");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("app", app.getAbsolutePath());
        capabilities.setCapability("appPackage", "com.markspryor.markingmachine");
        capabilities.setCapability("appActivity", "in.opencombine.instrument.ui.HomeActivity");
        driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.findElement(By.id("btnStartApp")).click();


}

}

If I run, Application gets install on real device and it shows following error :

Sep 08, 2017 4:09:51 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Sep 08, 2017 4:10:04 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {ELEMENT=1}
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'DTP315', ip: '10.219.1.17', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:375)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:417)
at io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:70)
at io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)
at org.openqa.selenium.By$ById.findElement(By.java:218)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at com.metatag.poc.DesignLayout.main(DesignLayout.java:46)
Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:373)
  • Shot in the dark. What if you just do driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); without casting to MobileElement? – alecxe Sep 8 '17 at 13:24
  • evenif I did without casting to MobileElement then also it is showing same error – PRasd Sep 11 '17 at 4:28
  • Did you find any resolution to this. I am also facing same issue. – Deepak Sep 12 '17 at 9:49
  • Tried with given version of Java client (java-client-5.0.0-BETA6) Its worked.... ! Thanks! – Rakesh Jan 15 '18 at 10:49
1

I was using following combination:

Appium : 1.6.5
Selenium : selenium-java-3.3.1
Appium Java Client : java-client-5.0.3

I downgraded the Appium client to:

Appium Java Client : java-client-5.0.0-BETA6

and the problem was solved.

I am not aware how/where to raise the issue of the version incompatibility issue.

  • looks like Appium has an issue with their latest version in converting some of the components to webdriver. I guess you can report it on their github or main site...doesn't look like you have the specifics with their code, but someone will hopefully know. – mutt Sep 13 '17 at 19:49
0

I found the solution, but can't explain how it works. But it works for me as a miracle.

Just add the below line, and magic happens. I don't have any idea how that makes it work:

capability.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "60");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.