This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
28 / 31
Nov 2017
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 ?

@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;
        }
    }

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

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

This broke for me all of a sudden with no changes to my dependencies or code (I was actually on vacation over the weekend) for weeks. I believe this started failing Friday 8/18 (We saw some other weird issues in another repo around dependencies, and had to force selenium 3.4.0 to ignore guava and force guava 21.0 as it was trying to use 23.0).

Indeed it appears as though the selenium 3.5.1 release has fouled up some older dependencies that may not have been specific enough, as my 3.3.0 selenium is “upgrading” to 3.5.1:

+--- org.seleniumhq.selenium:selenium-java:3.3.0
|    +--- org.seleniumhq.selenium:selenium-chrome-driver:3.3.0
|    |    \--- org.seleniumhq.selenium:selenium-remote-driver:3.3.0 -> 3.5.1
|    |         +--- org.seleniumhq.selenium:selenium-api:3.5.1
|    |         +--- cglib:cglib-nodep:3.2.4
|    |         +--- org.apache.commons:commons-exec:1.3
|    |         +--- commons-codec:commons-codec:1.10
|    |         +--- commons-logging:commons-logging:1.2
|    |         +--- com.google.code.gson:gson:2.8.0 -> 2.8.1
|    |         +--- com.google.guava:guava:23.0

Looks like the issue is in the selenium htmlunit dependency that’s grabbing 3.5.1 causing everythingelse to be upgraded

|    \--- org.seleniumhq.selenium:htmlunit-driver:2.24
|         +--- org.seleniumhq.selenium:selenium-support:[2.53.0,4.0.0) -> 3.5.1
|         |    +--- org.seleniumhq.selenium:selenium-api:3.5.1
|         |    +--- org.seleniumhq.selenium:selenium-remote-driver:3.5.1 (*)

To fix this, force seleniumjava to a version, then ignore guava from it (gradle example):

// Selenium 3.5.1 released, caused older selenium issues, so need to force guava to 21.0 and other
// sub-modules where we want them.  thanks htmlunit-driver!

// Uncomment this line, and remove bottom section if things get fixed or you upgrade
// all the way to selenium 3.5.1... but appium doesn't play well with it yet
// compile("org.seleniumhq.selenium:selenium-java:3.3.0")

// All this can go away if htmlunit-driver is fixed for older selenium versions
compile("io.appium:java-client:5.0.0-BETA9") {
    exclude group: 'org.seleniumhq.selenium', module: 'selenium-java'
}
compile("org.seleniumhq.selenium:selenium-java:3.3.0") {
    exclude group: 'org.seleniumhq.selenium', module: 'htmlunit-driver'
}
// If you need parts of htmlunit-driver dependencies, uncomment this
// compile("org.seleniumhq.selenium:htmlunit-driver:2.26") {
//     exclude group: 'org.seleniumhq.selenium', module: 'selenium-api'
//     exclude group: 'org.seleniumhq.selenium', module: 'selenium-support'
// }
compile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: "3.3.0"
// Make sure guava is 21.0... others don't play well
compile group: 'com.google.guava', name: 'guava', version: '21.0'
// If you need codec stuff from newer commons-codec
compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
1 month later

Yes selenium 3.5.1 is the culprit, downgrading to 3.4 had successfully able to locate native elements in Android

1 month later

I faced similar issue with iOS 11.0 and got resolved when i updated java-client to latest i.e., 5.0.4

26 days later
  1. Add commons-lang3-3.1.jar in library
  2. Use java-client-5.0.4.jar instead of previous version.

Your Problem will be solved.

1 month later

Hi All,

I am still getting same error eventhough I am using latest versions…

	<artifactId>java-client</artifactId>
	<version>4.1.2</version>

          <artifactId>selenium-java</artifactId>
            <version>3.8.1</version

Src:==>

public class StartApplication {

	private static AndroidDriver driver;

	
	public static void main() throws MalformedURLException, InterruptedException {

		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
		capabilities.setCapability("deviceName", "MotoG");
		capabilities.setCapability("platformVersion", "6.0");
		capabilities.setCapability("platformName", "Android");
		 capabilities.setCapability("appPackage", "abc.xys.test");
		capabilities.setCapability("appActivity", "abc.xys.test.HomeActivity");
		driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
		driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS); 
		Thread.sleep(10000);
		driver.findElementById("android:id/up").click();		
								

}

Console O/P ==>
java.lang.NullPointerException at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)

Please Help…