0
votes

Displaying the error as:
Returned value cannot be converted to WebElement: {element-6066-11e4-a52e-4f735466cecf=1, ELEMENT=1}

while executing the code:

DesiredCapabilities c=new DesiredCapabilities();
c.setCapability(CapabilityType.BROWSER_NAME, "");
c.setCapability("deviceName", "871cd2f2");
c.setCapability("platformName", "Android");
c.setCapability("platformversion", "4.3");
c.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "60");
c.setCapability("appPackage","com.android.vending");
c.setCapability("appActivity","com.google.android.finsky.activities.MainActivity");
URL U=new URL("http://127.0.0.1:4723/wd/hub");      
WebDriver driver=new AndroidDriver(U,c);        
//AppiumDriver d=new AndroidDriver(U,c);        
Thread.sleep(10000);        
MobileElement m=driver.findElement(By.xpath("//*[@content-desc='Search']"));
m.click();      
m.sendKeys("edthesis");

Appium console Error:

[Appium] Welcome to Appium v1.10.0 [Appium] Appium REST http interface listener started on 0.0.0.0:4723 [HTTP] --> POST /wd/hub/session [HTTP] {"desiredCapabilities":{"appActivity":"com.google.android.finsky.activities.MainActivity","appPackage":"com.android.vending","browserName":"","deviceName":"871cd2f2","newCommandTimeout":"60","platformName":"Android","platformversion":"4.3"},"capabilities":{"desiredCapabilities":{"appActivity":"com.google.android.finsky.activities.MainActivity","appPackage":"com.android.vending","browserName":"","deviceName":"871cd2f2","newCommandTimeout":"60","platformName":"Android","platformversion":"4.3"},"firstMatch":[{"browserName":"","platformName":"android"}]}} [W3C] Calling AppiumDriver.createSession() with args: [{"appActivity":"com.google.android.finsky.activities.MainActivity","appPackage":"com.android.vending","browserName":"","deviceName":"871cd2f2","newCommandTimeout":"60","platformName":"Android","platformversion":"4.3"},null,{"desiredCapabilities":{"appActivity":"com.google.android.finsky.activities.MainActivity","appPackage":"com.android.vending","browserName":"","deviceName":"871cd2f2","newCommandTimeout":"60","platformName":"Android","platformversion":"4.3"},"firstMatch":[{"browserName":"","platformName":"android"}]}] [BaseDriver] Event 'newSessionRequested' logged at 1552640850731 (14:37:30 GMT+0530 (India Standard Time)) [Appium] Could not parse W3C capabilities: 'deviceName' can't be blank [Appium] Trying to fix W3C capabilities by merging them with JSONWP caps [BaseDriver] The capabilities ["appActivity","appPackage","deviceName","newCommandTimeout","platformversion"] are not standard capabilities and should have an extension prefix [BaseDriver] Number capability passed in as string. Functionality may be compromised. [Appium] Creating new AndroidDriver (v4.8.0) session [Appium] Capabilities: [Appium]appActivity: com.google.android.finsky.activities.MainActivity [Appium] appPackage: com.android.vending [Appium] deviceName: 871cd2f2 [Appium] newCommandTimeout: 60 [Appium] platformversion: 4.3 [Appium] browserName: [Appium] platformName: android [BaseDriver] W3C capabilities {"alwaysMatch":{"appium:app... and MJSONWP desired capabilities {"appActivity":"com.google.... were provided [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"appium:app... [BaseDriver] Number capability passed in as string. Functionality may be compromised. [BaseDriver] Capability 'newCommandTimeout' changed from string ('60') to integer (60). This may cause unexpected behavior [BaseDriver] The following capabilities were provided, but are not recognized by appium: platformversion. [BaseDriver] Session created with session id: dd472778-35d6-45db-9ccf-57328cb2aa3f [AndroidDriver] Java version is: 1.8.0_151 [ADB] Checking whether adb is present [ADB] The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb. [ADB] Using adb from D:\Appium\Sdk\tools\adb.exe [ADB] [AndroidDriver] Retrieving device list [ADB] Trying to find a connected android device [ADB] Getting connected devices... [ADB] 1 device(s) connected [AndroidDriver] Using device: 871cd2f2 [ADB] Setting device id to 871cd2f2 [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell getprop ro.build.version.sdk' [ADB] Current device property 'ro.build.version.sdk': 18 [ADB] Device API level: 18 [AndroidDriver] App file was not listed, instead we're going to run com.android.vending directly on the device [AndroidDriver] Checking whether package is present on the device [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell pm list packages com.android.vending' [AndroidDriver] Starting Android session [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 wait-for-device' [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell echo ping' [AndroidDriver] Pushing settings apk to device... [ADB] Getting install status for io.appium.settings [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell dumpsys package io.appium.settings' [ADB] 'io.appium.settings' is installed [ADB] Getting package info for 'io.appium.settings' [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell dumpsys package io.appium.settings' [ADB] Checking whether aapt is present [ADB] The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for aapt. [ADB] Using aapt from D:\Appium\Sdk\build-tools\26.0.1\aapt.exe [ADB] [ADB] The version name of the installed 'io.appium.settings' is greater or equal to the application version name ('2.11.0' >= '2.11.0') [ADB] There is no need to install/upgrade 'C:\Users\preethi.g\AppData\Local\appium-desktop\app-1.10.0\resources\app\node_modules\io.appium.settings\apks\settings_apk-debug.apk' [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell ps' [ADB] Device API level: 18 [AndroidDriver] Granting android.permission.SET_ANIMATION_SCALE, CHANGE_CONFIGURATION, ACCESS_FINE_LOCATION by pm grant [ADB] Granting permissions ["android.permission.SET_ANIMATION_SCALE","android.permission.CHANGE_CONFIGURATION","android.permission.ACCESS_FINE_LOCATION"] to 'io.appium.settings' [ADB] Got the following command chunks to execute: [["pm","grant","io.appium.settings","android.permission.SET_ANIMATION_SCALE",";","pm","grant","io.appium.settings","android.permission.CHANGE_CONFIGURATION",";","pm","grant","io.appium.settings","android.permission.ACCESS_FINE_LOCATION",";"]] [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell pm grant io.appium.settings android.permission.SET_ANIMATION_SCALE \; pm grant io.appium.settings android.permission.CHANGE_CONFIGURATION \; pm grant io.appium.settings android.permission.ACCESS_FINE_LOCATION \;' [ADB] Device API level: 18 [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 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: 18 [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell settings put secure mock_location 1' [Logcat] Starting logcat capture [ADB] Getting device platform version [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell getprop ro.build.version.release' [ADB] Current device property 'ro.build.version.release': 4.3 [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell wm size' [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell getprop ro.product.model' [ADB] Current device property 'ro.product.model': SAMSUNG-SGH-I747 [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell getprop ro.product.manufacturer' [ADB] Current device property 'ro.product.manufacturer': samsung [AndroidDriver] No app sent in, not parsing package/activity [AndroidDriver] No app capability. Assuming it is already on the device [ADB] Getting install status for com.android.vending [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell dumpsys package com.android.vending' [ADB] 'com.android.vending' is installed [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell am force-stop com.android.vending' [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell pm clear com.android.vending' [AndroidDriver] Performed fast reset on the installed 'com.android.vending' application (stop and clear) [AndroidBootstrap] Watching for bootstrap disconnect [ADB] Forwarding system: 4724 to device: 4724 [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 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 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 push C:\Users\preethi.g\AppData\Local\appium-desktop\app-1.10.0\resources\app\node_modules\appium-android-driver\bootstrap\bin\AppiumBootstrap.jar /data/local/tmp/' [ADB] Attempting to kill all uiautomator processes [ADB] Getting all processes with uiautomator [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell ps' [ADB] No 'uiautomator' process has been found [UiAutomator] Starting UIAutomator [ADB] Creating ADB subprocess with args: ["-P",5037,"-s","871cd2f2","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.android.vending","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false] [UiAutomator] Moving to state 'online' [AndroidBootstrap] Android bootstrap socket is now connected [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell dumpsys window' [AndroidBootstrap] [BOOTSTRAP LOG] [debug] json loading complete. [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers. [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected [AndroidDriver] Screen already unlocked, doing nothing [ADB] Device API level: 18 [ADB] Running 'D:\Appium\Sdk\tools\adb.exe -P 5037 -s 871cd2f2 shell am start -W -n com.android.vending/com.google.android.finsky.activities.MainActivity -S' [Appium] New AndroidDriver session created successfully, session dd472778-35d6-45db-9ccf-57328cb2aa3f added to master session list [BaseDriver] Event 'newSessionStarted' logged at 1552640881307 (14:38:01 GMT+0530 (India Standard Time)) [W3C (dd472778)] Cached the protocol value 'W3C' for the new session dd472778-35d6-45db-9ccf-57328cb2aa3f [W3C (dd472778)] Responding to client with driver.createSession() result: {"capabilities":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"browserName":"","platformName":"android","appActivity":"com.google.android.finsky.activities.MainActivity","appPackage":"com.android.vending","deviceName":"871cd2f2","newCommandTimeout":60,"platformversion":"4.3"},"browserName":"","platformName":"android","appActivity":"com.google.android.finsky.activities.MainActivity","appPackage":"com.android.vending","deviceName":"871cd2f2","newCommandTimeout":60,"platformversion":"4.3","deviceUDID":"871cd2f2","platformVersion":"4.3","deviceScreenSize":"720x1280","deviceModel":"SAMSUNG-SGH-I747","deviceManufacturer":"samsung"}} [HTTP] <-- POST /wd/hub/session 200 30591 ms - 855 [HTTP] [HTTP] --> POST /wd/hub/session/dd472778-35d6-45db-9ccf-57328cb2aa3f/element [HTTP] {"value":"//[@content-desc='Search']","using":"xpath"} [W3C (dd472778)] Calling AppiumDriver.findElement() with args: ["xpath","//[@content-desc='Search']","dd472778-35d6-45db-9ccf-57328cb2aa3f"] [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":"xpath","selector":"//[@content-desc='Search']","context":"","multiple":false}} [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//[@content-desc='Search']","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 '//*[@content-desc='Search']' using 'XPATH' with the contextId: '' multiple: false [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.ImageView, INSTANCE=6] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":{"ELEMENT":"1"},"status":0} [AndroidBootstrap] Received command result from bootstrap [W3C (dd472778)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"1","ELEMENT":"1"} [HTTP] <-- POST /wd/hub/session/dd472778-35d6-45db-9ccf-57328cb2aa3f/element 200 1977 ms - 67 [HTTP]

3
you don't need to use BROWSER_NAME capability if you are testing the android app. Remove it and try to run the code.Suban Dhyako
Tried still displaying the same errorPreethi reddy goli
try AppiumDriver instead of WebDriver. Can you add the appium server log?Suban Dhyako
Tried with AppiumDriver displaying the same error and updated the appium console log please checkPreethi reddy goli
It looks like the connection is successful, but the cryptic returned message in the log makes me think it found more than one match. Trying using either findElements (plural) into a List or add additional specs to your xpath to isolate which one of the multiple elements you want by including some other attribute.Bill Hileman

3 Answers

0
votes

First try to get the relevant code from the Appium Inspector session itself. You can execute your actions on the connected device and record them to generate correct code for finding the relevant element.

I have tried below on Android with my application. Hope might help you

DesiredCapabilities c=new DesiredCapabilities();
c.setCapability(CapabilityType.BROWSER_NAME, "");
c.setCapability("deviceName", "871cd2f2");
c.setCapability("platformName", "Android");
c.setCapability("platformversion", "4.3");

// Android version is 4.3, try with heigher version emulator as well

c.setCapability("automationName", "UiAutomator2");
c.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "60");
c.setCapability("appPackage","com.android.vending");
c.setCapability("appActivity","com.google.android.finsky.activities.MainActivity");
URL U=new URL("http://127.0.0.1:4723/wd/hub");  

AppiumDriver driver = new AppiumDriver(U,c); 

Thread.sleep(10000);  

MobileElement m = driver.findElementByXpath("//*[@content desc='Search']"));
m.click();      
m.sendKeys("edthesis");
0
votes

Try with Androiddriver instead of appium driver AndroidDriver driver=new AndroidDriver<>(new URL("http://0.0.0.0:4723/wd/hub"),cap);

If not working then try by updating java client jar

0
votes

Update your java client to 6.0.0-BETA3 in maven dependency POM.XML file. It worked for me as 6.0.0-BETA3 comes with W3C compliance

<dependency><groupId>io.appium</groupId><artifactId>java-client</artifactId<version>6.0.0-BETA3</version></dependency>

Please find the details here: https://github.com/appium/java-client