RemoteWebElement can not be cast to io.appium.java_client.android.AndroidElement

Hi I am getting below error -
Exception in thread “main” java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.android.AndroidElement
at Base.main(Base.java:12)

I am using -
java-client-5.0.0-BETA9
appium v1.6.5.

Here is a snipped code

    import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
public class TestOne {

	public static AndroidDriver<AndroidElement> Capabilities() throws MalformedURLException {
	 AndroidDriver<AndroidElement>  driver;
	 File appDir = new File("src");
     File app = new File(appDir, "ApiDemos-debug.apk");
     DesiredCapabilities capabilities = new DesiredCapabilities();
     capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus");
     capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
     driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
	 return driver;
	}

}

base.java

import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;

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

public class Base extends TestOne {

	public static void main(String[] args) throws MalformedURLException {
		AndroidDriver<AndroidElement>driver=Capabilities();
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		driver.findElementByXPath("//android.widget.TextView[@text='Preference']").click();
	}

}

Please help me to resolve this issue.

instead of specifying a type , just leave AndroidDriver generic like below

AndroidDriver<?>

1 Like

By keeping AndroidDriver generic getting below error.

Exception in thread “main” java.lang.NullPointerException
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:275)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:82)
at Base.main(Base.java:12)

can you share the modified code and full stacktrace

@Shivaji_Ghadge try to change:

 AndroidDriver<AndroidElement>driver=Capabilities(); -> driver = Capabilities();

@harigovind
Here it is the modified code
package co;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

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

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class Base {

	public static void main(String[] args) throws MalformedURLException {
		
		AndroidDriver<?>  driver;
		File appDir = new File("src");
		File app = new File(appDir, "ApiDemos-debug.apk");
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus");
		capabilities.setCapability(MobileCapabilityType.APP,app.getAbsolutePath());
		driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
		driver.findElementByXPath("//android.widget.TextView[@text='Preference']").click();
	}
}
1 Like

hmm , can’t find anything wrong in the code ,
Can you check SDK path is set , ANDROID_HOME environment variable is added , since you are passing apk , aapt is required to extract app package and launch activity.

please share full stacktrace and server log as well .

@harigovind

Yep… Here is path ----PATH=C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.8.0_144\bin;C:\Users\shiva\AppData\Local\Android\sdk\tools\bin;C:\Users\shiva\AppData\Local\Android\sdk\tools;C:\Users\shiva\AppData\Local\Android\sdk\platform-tools;C:\Program Files\nodejs\;C:\Program Files\nodejs\node_modules\npm\bin;C:\Users\shiva\AppData\Local\Microsoft\WindowsApps;C:\Users\shiva\AppData\Roaming\npm

Appium Server Log-

Microsoft Windows [Version 10.0.15063]
© 2017 Microsoft Corporation. All rights reserved.

C:\Users\shiva>appium
[Appium] Welcome to Appium v1.6.5
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> POST /wd/hub/session {"capabilities":[{"desiredCapabilities":{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"}},{"requiredCapabilities":{}}],"desiredCapabilities":{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"},"requiredCapabilities":{}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"},{},[{"desiredCapabilities":{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"}},{"requiredCapabilities":{}}]]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1502880133964 (03:42:13 GMT-0700 (Pacific Daylight Time))
[Appium] Creating new AndroidDriver (v1.20.0) session
[Appium] Capabilities:
[Appium]   app: 'D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk'
[Appium]   platformName: 'Android'
[Appium]   deviceName: 'Nexus'
[debug] [AndroidDriver] AndroidDriver version: 1.20.0
[BaseDriver] Session created with session id: 5521afad-150d-4e7f-a200-a319ff8f3c3a
[debug] [AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_144
[ADB] Checking whether adb is present
[ADB] Using adb.exe from C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[AndroidDriver] Using device: emulator-5554
[ADB] Checking whether adb is present
[ADB] Using adb.exe from C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe
[debug] [ADB] Setting device id to emulator-5554
[BaseDriver] Using local app 'D:\workplace\Appium\AppiumTest\src\ApiDemos-debug.apk'
[debug] [AndroidDriver] Checking whether app is actually present
[AndroidDriver] Starting Android session
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","wait-for-device"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","echo","ping"]
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","list","packages","io.appium.settings"]
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for io.appium.settings
[debug] [ADB] Getting connected devices...
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from C:\Users\shiva\AppData\Local\Android\sdk\build-tools\25.0.3\aapt.exe
[ADB] Cannot read version codes of C:\Users\shiva\AppData\Roaming\npm\node_modules\appium\node_modules\io.appium.settings\app\build\outputs\apk\settings_apk-debug.apk and/or io.appium.settings. Assuming correct app version is already installed
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","package","io.appium.settings"]
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.build.version.sdk"]
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","package","io.appium.settings"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","dump","io.appium.settings"]
[debug] [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,;
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";"]
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";"]
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","install","C:\\Users\\shiva\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-unlock\\bin\\unlock_apk-debug.apk"]
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","install","C:\\Users\\shiva\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-unlock\\bin\\unlock_apk-debug.apk"]
[debug] [ADB] Application 'C:\Users\shiva\AppData\Roaming\npm\node_modules\appium\node_modules\appium-unlock\bin\unlock_apk-debug.apk' already installed. Continuing.
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","appops","set","io.appium.settings","android:mock_location","allow"]
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.build.version.release"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","wm","size"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.product.model"]
[debug] [ADB] Current device property 'ro.product.model': Android SDK built for x86
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.product.manufacturer"]
[debug] [ADB] Current device property 'ro.product.manufacturer': unknown
[debug] [AndroidDriver] Parsing package and activity from app manifest
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from C:\Users\shiva\AppData\Local\Android\sdk\build-tools\25.0.3\aapt.exe
[ADB] Extracting package and launch activity from manifest
[debug] [ADB] badging package: io.appium.android.apis
[debug] [ADB] badging act: io.appium.android.apis.ApiDemos
[debug] [AndroidDriver] Parsed package and activity are: io.appium.android.apis/io.appium.android.apis.ApiDemos
[AndroidDriver] Remote apk path is /data/local/tmp/29649242b53e9a67ba855b067422713c.apk
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","ls","/data/local/tmp/29649242b53e9a67ba855b067422713c.apk"]
[debug] [AndroidDriver] Checking if app is installed
[debug] [ADB] Getting install status for io.appium.android.apis
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","list","packages","io.appium.android.apis"]
[debug] [ADB] App is installed
[AndroidDriver] Apk is already on remote and installed, resetting
[debug] [AndroidDriver] Running fast reset (stop and clear)
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","am","force-stop","io.appium.android.apis"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","clear","io.appium.android.apis"]
[debug] [AndroidDriver] Extracting strings from apk D:\workplace\Appium\AppiumTest\src\ApiDemos-debug.apk null C:\Users\shiva\AppData\Local\Temp\io.appium.android.apis
[debug] [ADB] Extracting strings for language: default
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","persist.sys.locale"]
[debug] [ADB] Current device property 'persist.sys.locale':
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.product.locale"]
[debug] [ADB] Current device property 'ro.product.locale': en-US
[debug] [ADB] No strings.xml for language 'en', getting default strings.xml
[debug] [ADB] Reading strings from converted strings.json
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","push","C:\\Users\\shiva\\AppData\\Local\\Temp\\io.appium.android.apis\\strings.json","/data/local/tmp"]
[debug] [AndroidBootstrap] Watching for bootstrap disconnect
[debug] [ADB] Forwarding system: 4724 to device: 4724
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","forward","tcp:4724","tcp:4724"]
[debug] [UiAutomator] Starting UiAutomator
[debug] [UiAutomator] Moving to state 'starting'
[debug] [UiAutomator] Parsing uiautomator jar
[debug] [UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","push","C:\\Users\\shiva\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-android-bootstrap\\bootstrap\\bin\\AppiumBootstrap.jar","/data/local/tmp/"]
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Starting UIAutomator
[debug] [ADB] Creating ADB subprocess with args: ["-P",5037,"-s","emulator-5554","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","io.appium.android.apis","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[debug] [UiAutomator] Moving to state 'online'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] json loading complete.
[AndroidBootstrap] Android bootstrap socket is now connected
[debug] [ADB] Getting connected devices...
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","window"]
[AndroidDriver] Screen already unlocked, doing nothing
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","am","start","-W","-n","io.appium.android.apis/io.appium.android.apis.ApiDemos","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Waiting for activity matching pkg: 'io.appium.android.apis' and activity: 'io.appium.android.apis.ApiDemos' to be focused
[debug] [ADB] Possible activities, to be checked: io.appium.android.apis.ApiDemos, io.appium.android.apis.io.appium.android.apis.ApiDemos
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","window","windows"]
[debug] [ADB] Found package: 'io.appium.android.apis' and fully qualified activity name : 'io.appium.android.apis.ApiDemos'
[Appium] New AndroidDriver session created successfully, session 5521afad-150d-4e7f-a200-a319ff8f3c3a added to master session list
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1502880141320 (03:42:21 GMT-0700 (Pacific Daylight Time))
[debug] [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":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"},"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"emulator-5554","deviceUDID":"emulator-5554","platformVersion":"7.1.1","deviceScreenSize":"1440x2560","deviceModel":"Android SDK built for x86","deviceManufacturer":"unknown","appPackage":"io.appium.android.apis","appWaitPackage":"io.appium.android.apis","appActivity":"io.appium.android.apis.ApiDemos","appWaitActivity":"io.appium.android.apis.ApiDemos"}
[HTTP] <-- POST /wd/hub/session 200 7368 ms - 852
[HTTP] --> GET /wd/hub/session/5521afad-150d-4e7f-a200-a319ff8f3c3a {}
[debug] [MJSONWP] Calling AppiumDriver.getSession() with args: ["5521afad-150d-4e7f-a200-a319ff8f3c3a"]
[debug] [MJSONWP] Responding to client with driver.getSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"},"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"emulator-5554","deviceUDID":"emulator-5554","platformVersion":"7.1.1","deviceScreenSize":"1440x2560","deviceModel":"Android SDK built for x86","deviceManufacturer":"unknown","appPackage":"io.appium.android.apis","appWaitPackage":"io.appium.android.apis","appActivity":"io.appium.android.apis.ApiDemos","appWaitActivity":"io.appium.android.apis.ApiDemos"}
[HTTP] <-- GET /wd/hub/session/5521afad-150d-4e7f-a200-a319ff8f3c3a 200 15 ms - 852
[HTTP] --> GET /wd/hub/session/5521afad-150d-4e7f-a200-a319ff8f3c3a {}
[debug] [MJSONWP] Calling AppiumDriver.getSession() with args: ["5521afad-150d-4e7f-a200-a319ff8f3c3a"]
[debug] [MJSONWP] Responding to client with driver.getSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"},"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"emulator-5554","deviceUDID":"emulator-5554","platformVersion":"7.1.1","deviceScreenSize":"1440x2560","deviceModel":"Android SDK built for x86","deviceManufacturer":"unknown","appPackage":"io.appium.android.apis","appWaitPackage":"io.appium.android.apis","appActivity":"io.appium.android.apis.ApiDemos","appWaitActivity":"io.appium.android.apis.ApiDemos"}
[HTTP] <-- GET /wd/hub/session/5521afad-150d-4e7f-a200-a319ff8f3c3a 200 10 ms - 852
[HTTP] --> POST /wd/hub/session/5521afad-150d-4e7f-a200-a319ff8f3c3a/timeouts {"type":"implicit","ms":10000}
[debug] [MJSONWP] Calling AppiumDriver.timeouts() with args: ["implicit",10000,"5521afad-150d-4e7f-a200-a319ff8f3c3a"]
[debug] [BaseDriver] Set implicit wait to 10000ms
[debug] [MJSONWP] Responding to client with driver.timeouts() result: null
[HTTP] <-- POST /wd/hub/session/5521afad-150d-4e7f-a200-a319ff8f3c3a/timeouts 200 5 ms - 76
[HTTP] --> POST /wd/hub/session/5521afad-150d-4e7f-a200-a319ff8f3c3a/element {"using":"xpath","value":"//android.widget.TextView[@text='Preference']"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["xpath","//android.widget.TextView[@text='Preference']","5521afad-150d-4e7f-a200-a319ff8f3c3a"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 10000 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.TextView[@text='Preference']","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.TextView[@text='Preference']","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 '//android.widget.TextView[@text='Preference']' using 'XPATH' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.TextView, INSTANCE=9]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"1"}}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"1"}
[HTTP] <-- POST /wd/hub/session/5521afad-150d-4e7f-a200-a319ff8f3c3a/element 200 96 ms - 87

Looks all fine from log… are you still getting NullPointer exception ? may be surrounding code with try catch will help to nail down the problem .

No Error in console if we put it into try-catch block.

But driver.findElementByXPath("//android.widget.TextView[@text=‘Preference’]").click(); does not click on this element.
On emulator application get opened but not clicking on xpath element.
Can you please tell me how to varify element is present on the screen. Thanks

@harigovind

By putting code into try catch as below
package co;

import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import io.appium.java_client.android.AndroidDriver;

public class Base extends TestOne {

	public static void main(String[] args) throws MalformedURLException {
		try {
			AndroidDriver<?>driver=Capabilities();
			driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
			driver.findElementByAndroidUIAutomator("text(\"Preference\")").click();
			//driver.findElementByXPath("//android.widget.TextView[@text='Preference']").click();
		}
		catch (Exception e) {
			 System.out.println(e.getMessage() );
		}
	}
}

I am getting “null” value in cansole.
Can you explain me it.
Thanks

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class Base {

	public static void main(String[] args)  {

		try {
			AndroidDriver<?> driver;
			File appDir = new File("src");
			File app = new File(appDir, "ApiDemos-debug.apk");
			DesiredCapabilities capabilities = new DesiredCapabilities();
			capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus");
			capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
			driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
			
			WebDriverWait wait = new WebDriverWait(driver, 30);
			WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@text='Preference']")));
			
			driver.findElementByXPath("//*[@text='Preference']").click();
		
		} catch (Exception e) {

			e.printStackTrace();
		}
	}
}

Try this code

Hello @harigovind i tried above code and getting NullPointerExcpetion in console

java.lang.NullPointerException
	at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:275)
	at org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:316)
	at org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:302)
	at org.openqa.selenium.support.ui.ExpectedConditions.access$100(ExpectedConditions.java:44)
	at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:206)
	at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:202)
	at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:644)
	at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:641)
	at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:209)
	at co.test.main(test.java:30)

Server Log -

Microsoft Windows [Version 10.0.15063]
© 2017 Microsoft Corporation. All rights reserved.

C:\Users\shiva>appium
[Appium] Welcome to Appium v1.6.5
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> POST /wd/hub/session {"capabilities":[{"desiredCapabilities":{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"}},{"requiredCapabilities":{}}],"desiredCapabilities":{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"},"requiredCapabilities":{}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"},{},[{"desiredCapabilities":{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"}},{"requiredCapabilities":{}}]]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1502947812356 (22:30:12 GMT-0700 (Pacific Daylight Time))
[Appium] Creating new AndroidDriver (v1.20.0) session
[Appium] Capabilities:
[Appium]   app: 'D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk'
[Appium]   platformName: 'Android'
[Appium]   deviceName: 'Nexus'
[debug] [AndroidDriver] AndroidDriver version: 1.20.0
[BaseDriver] Session created with session id: 05581c22-382b-42fc-9906-1fbfb17a6854
[debug] [AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_144
[ADB] Checking whether adb is present
[ADB] Using adb.exe from C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[AndroidDriver] Using device: emulator-5554
[ADB] Checking whether adb is present
[ADB] Using adb.exe from C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe
[debug] [ADB] Setting device id to emulator-5554
[BaseDriver] Using local app 'D:\workplace\Appium\AppiumTest\src\ApiDemos-debug.apk'
[debug] [AndroidDriver] Checking whether app is actually present
[AndroidDriver] Starting Android session
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","wait-for-device"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","echo","ping"]
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","list","packages","io.appium.settings"]
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for io.appium.settings
[debug] [ADB] Getting connected devices...
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from C:\Users\shiva\AppData\Local\Android\sdk\build-tools\25.0.3\aapt.exe
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","package","io.appium.settings"]
[ADB] Cannot read version codes of C:\Users\shiva\AppData\Roaming\npm\node_modules\appium\node_modules\io.appium.settings\app\build\outputs\apk\settings_apk-debug.apk and/or io.appium.settings. Assuming correct app version is already installed
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.build.version.sdk"]
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","package","io.appium.settings"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","dump","io.appium.settings"]
[debug] [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,;
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";"]
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";"]
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","install","C:\\Users\\shiva\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-unlock\\bin\\unlock_apk-debug.apk"]
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","install","C:\\Users\\shiva\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-unlock\\bin\\unlock_apk-debug.apk"]
[debug] [ADB] Application 'C:\Users\shiva\AppData\Roaming\npm\node_modules\appium\node_modules\appium-unlock\bin\unlock_apk-debug.apk' already installed. Continuing.
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","appops","set","io.appium.settings","android:mock_location","allow"]
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.build.version.release"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","wm","size"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.product.model"]
[debug] [ADB] Current device property 'ro.product.model': Android SDK built for x86
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.product.manufacturer"]
[debug] [ADB] Current device property 'ro.product.manufacturer': unknown
[debug] [AndroidDriver] Parsing package and activity from app manifest
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from C:\Users\shiva\AppData\Local\Android\sdk\build-tools\25.0.3\aapt.exe
[ADB] Extracting package and launch activity from manifest
[debug] [ADB] badging package: io.appium.android.apis
[debug] [ADB] badging act: io.appium.android.apis.ApiDemos
[debug] [AndroidDriver] Parsed package and activity are: io.appium.android.apis/io.appium.android.apis.ApiDemos
[AndroidDriver] Remote apk path is /data/local/tmp/29649242b53e9a67ba855b067422713c.apk
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","ls","/data/local/tmp/29649242b53e9a67ba855b067422713c.apk"]
[debug] [AndroidDriver] Checking if app is installed
[debug] [ADB] Getting install status for io.appium.android.apis
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","list","packages","io.appium.android.apis"]
[debug] [ADB] App is installed
[AndroidDriver] Apk is already on remote and installed, resetting
[debug] [AndroidDriver] Running fast reset (stop and clear)
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","am","force-stop","io.appium.android.apis"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","pm","clear","io.appium.android.apis"]
[debug] [AndroidDriver] Extracting strings from apk D:\workplace\Appium\AppiumTest\src\ApiDemos-debug.apk null C:\Users\shiva\AppData\Local\Temp\io.appium.android.apis
[debug] [ADB] Extracting strings for language: default
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","persist.sys.locale"]
[debug] [ADB] Current device property 'persist.sys.locale':
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.product.locale"]
[debug] [ADB] Current device property 'ro.product.locale': en-US
[debug] [ADB] No strings.xml for language 'en', getting default strings.xml
[debug] [ADB] Reading strings from converted strings.json
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","push","C:\\Users\\shiva\\AppData\\Local\\Temp\\io.appium.android.apis\\strings.json","/data/local/tmp"]
[debug] [AndroidBootstrap] Watching for bootstrap disconnect
[debug] [ADB] Forwarding system: 4724 to device: 4724
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","forward","tcp:4724","tcp:4724"]
[debug] [UiAutomator] Starting UiAutomator
[debug] [UiAutomator] Moving to state 'starting'
[debug] [UiAutomator] Parsing uiautomator jar
[debug] [UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","push","C:\\Users\\shiva\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-android-bootstrap\\bootstrap\\bin\\AppiumBootstrap.jar","/data/local/tmp/"]
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Starting UIAutomator
[debug] [ADB] Creating ADB subprocess with args: ["-P",5037,"-s","emulator-5554","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","io.appium.android.apis","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[debug] [UiAutomator] Moving to state 'online'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Loading json...
[AndroidBootstrap] Android bootstrap socket is now connected
[debug] [ADB] Getting connected devices...
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] json loading complete.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","window"]
[AndroidDriver] Screen already unlocked, doing nothing
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","am","start","-W","-n","io.appium.android.apis/io.appium.android.apis.ApiDemos","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Waiting for activity matching pkg: 'io.appium.android.apis' and activity: 'io.appium.android.apis.ApiDemos' to be focused
[debug] [ADB] Possible activities, to be checked: io.appium.android.apis.ApiDemos, io.appium.android.apis.io.appium.android.apis.ApiDemos
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","window","windows"]
[debug] [ADB] Found package: 'io.appium.android.apis' and fully qualified activity name : 'io.appium.android.apis.ApiDemos'
[Appium] New AndroidDriver session created successfully, session 05581c22-382b-42fc-9906-1fbfb17a6854 added to master session list
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1502947819990 (22:30:19 GMT-0700 (Pacific Daylight Time))
[debug] [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":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"},"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"emulator-5554","deviceUDID":"emulator-5554","platformVersion":"7.1.1","deviceScreenSize":"1440x2560","deviceModel":"Android SDK built for x86","deviceManufacturer":"unknown","appPackage":"io.appium.android.apis","appWaitPackage":"io.appium.android.apis","appActivity":"io.appium.android.apis.ApiDemos","appWaitActivity":"io.appium.android.apis.ApiDemos"}
[HTTP] <-- POST /wd/hub/session 200 7648 ms - 852
[HTTP] --> GET /wd/hub/session/05581c22-382b-42fc-9906-1fbfb17a6854 {}
[debug] [MJSONWP] Calling AppiumDriver.getSession() with args: ["05581c22-382b-42fc-9906-1fbfb17a6854"]
[debug] [MJSONWP] Responding to client with driver.getSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"},"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"emulator-5554","deviceUDID":"emulator-5554","platformVersion":"7.1.1","deviceScreenSize":"1440x2560","deviceModel":"Android SDK built for x86","deviceManufacturer":"unknown","appPackage":"io.appium.android.apis","appWaitPackage":"io.appium.android.apis","appActivity":"io.appium.android.apis.ApiDemos","appWaitActivity":"io.appium.android.apis.ApiDemos"}
[HTTP] <-- GET /wd/hub/session/05581c22-382b-42fc-9906-1fbfb17a6854 200 8 ms - 852
[HTTP] --> GET /wd/hub/session/05581c22-382b-42fc-9906-1fbfb17a6854 {}
[debug] [MJSONWP] Calling AppiumDriver.getSession() with args: ["05581c22-382b-42fc-9906-1fbfb17a6854"]
[debug] [MJSONWP] Responding to client with driver.getSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"Nexus"},"app":"D:\\workplace\\Appium\\AppiumTest\\src\\ApiDemos-debug.apk","platformName":"Android","deviceName":"emulator-5554","deviceUDID":"emulator-5554","platformVersion":"7.1.1","deviceScreenSize":"1440x2560","deviceModel":"Android SDK built for x86","deviceManufacturer":"unknown","appPackage":"io.appium.android.apis","appWaitPackage":"io.appium.android.apis","appActivity":"io.appium.android.apis.ApiDemos","appWaitActivity":"io.appium.android.apis.ApiDemos"}
[HTTP] <-- GET /wd/hub/session/05581c22-382b-42fc-9906-1fbfb17a6854 200 4 ms - 852
[HTTP] --> POST /wd/hub/session/05581c22-382b-42fc-9906-1fbfb17a6854/elements {"using":"xpath","value":"//*[@text='Preference']"}
[debug] [MJSONWP] Calling AppiumDriver.findElements() with args: ["xpath","//*[@text='Preference']","05581c22-382b-42fc-9906-1fbfb17a6854"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[@text='Preference']","context":"","multiple":true}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[@text='Preference']","context":"","multiple":true}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//*[@text='Preference']' using 'XPATH' with the contextId: '' multiple: true
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.TextView, INSTANCE=9]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.TextView, INSTANCE=9]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Selector ends with instance.
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.findElements() result: [{"ELEMENT":"1"}]
[HTTP] <-- POST /wd/hub/session/05581c22-382b-42fc-9906-1fbfb17a6854/elements 200 104 ms - 89
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":[{"ELEMENT":"1"}]}
[BaseDriver] Shutting down because we waited 60 seconds for a command
[debug] [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 05581c22-382b-42fc-9906-1fbfb17a6854 from our master session list
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","am","force-stop","io.appium.android.apis"]
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","input","keyevent",3]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state 'stopping'
[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] [BOOTSTRAP LOG] [debug] Closed client connection
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: current=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: 0
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=
[debug] [AndroidBootstrap] [UIAUTO STDOUT] Test results for WatcherResultPrinter=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] Time: 63.707
[debug] [AndroidBootstrap] [UIAUTO STDOUT] OK (1 test)
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: -1
[debug] [UiAutomator] UiAutomator shut down normally
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [Logcat] Stopping logcat capture
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\shiva\AppData\Local\Android\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","emulator-5554","shell","am","force-stop","io.appium.unlock"]
[debug] [AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.

Is this issue with elements? or something else ?


Here is thhe screenshot of UIAutomator

@Shivaji_Ghadge
do not use CLICK use TAP instead.

    public boolean tapElement(MobileElement element) {
        try {
            new TouchAction((MobileDriver) driver).press(element).waitAction(Duration.ofMillis(70)).release().perform();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
1 Like

should try @Aleksei s suggestion , clickable is false from UI

After lots of R&D came across main issue…
Exact issue is with library earlier i was using
java-client-5.0.0-BETA9
client-combined-3.5.0-nodeps.jar

Now i have changed it to

java-client-1.2.1.jar
selenium-server-standalone-2.37.0.jar

1 Like

@Shivaji_Ghadge i am using same “5.0.0-BETA9” with latest appium 1.6.6-beta4 and same ApiDemos with 0 problems :slight_smile:
more over if you want automatically scroll to any menu item (there are some menus in client that are outside the screen) inside ApiDemos here is example:

    public Boolean tapCellByTitle(String title) {
        List<AndroidElement> elementList = driver.findElements(MobileBy.AndroidUIAutomator(
                "new UiScrollable(new UiSelector().resourceIdMatches(\".*id/list\")).setMaxSearchSwipes(5).scrollIntoView("
                        + "new UiSelector().text(\"" + title + "\"))"));
        if (elementList.isEmpty())
            return false;
        else
            return tapElement(elementList.get(0));
    }
1 Like

Oops Let me try thanks

@Aleksei can you please copy paste your code here. It will help me to get out from this.