Error with executing simple Click

Hi there trying to get a simple click to work but running into warious errors. my code is as follows.

import static org.junit.Assert.*;

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

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ByIdOrName;
import org.openqa.selenium.support.ui.ExpectedConditions;

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

public class desiredcapa {

@Test
public void test() throws MalformedURLException {

DesiredCapabilities cap=new DesiredCapabilities();
	File appDir = new File("C:/testing apks");
	
	File app = new File(appDir, "checkers_android_20150921_v2.2.35.apk");

cap.setCapability(MobileCapabilityType.PLATFORM_NAME , "Android");
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Gravy train(GT-I9190)");
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.2.2");

cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "100");
cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
AndroidDriver driver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);

   
//driver.findElementsByAndroidUIAutomator("new UiSelector().text('Browse')").click();
//driver.findElementsByXPath('//text[@value="Sign In"]').click();
//driver.findElement(By.xpath("//text[@id='Browse']")).click();
WebElement browse = driver.findElement(By.xpath("//android.widget.Button[@id='Browse'"));
browse.click();


}

}

This is the appium logs. DO i have to input APP package and APP activity?

info: [debug] Waiting for pkg “za.co.shoprite.eezicoupon” and activity “za.co.shoprite.eezicoupon.ui.activities.SplashActivity” to be focused
info: [debug] Getting focused package and activity
info: [debug] executing cmd: C:\Users\Dainese\AppData\Local\Android\sdk\platform-tools\adb.exe -s 20cbcdd4 shell “dumpsys window windows”
info: [debug] executing cmd: C:\Users\Dainese\AppData\Local\Android\sdk\platform-tools\adb.exe -s 20cbcdd4 shell “getprop ro.build.version.release”
info: [debug] Device is at release version 4.2.2
info: [debug] Device launched! Ready for commands
info: [debug] Setting command timeout to 100 secs
info: [debug] Appium session started with sessionId 704a9f7c-00c2-4846-bb88-a4d138a8b86a
info: ← POST /wd/hub/session 303 16839.172 ms - 74
info: → GET /wd/hub/session/704a9f7c-00c2-4846-bb88-a4d138a8b86a {}
info: [debug] Responding to client with success: {“status”:0,“value”:{“platform”:“LINUX”,“browserName”:“Android”,“platformVersion”:“4.2.2”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“app”:“C:\testing apks\checkers_android_20150921_v2.2.35.apk”,“platformName”:“Android”,“deviceName”:“Gravy train(GT-I9190)”,“newCommandTimeout”:“100”,“platformVersion”:“4.2.2”},“app”:“C:\testing apks\checkers_android_20150921_v2.2.35.apk”,“platformName”:“Android”,“deviceName”:“20cbcdd4”,“newCommandTimeout”:“100”},“sessionId”:“704a9f7c-00c2-4846-bb88-a4d138a8b86a”}
info: ← GET /wd/hub/session/704a9f7c-00c2-4846-bb88-a4d138a8b86a 200 3.520 ms - 646 {“status”:0,“value”:{“platform”:“LINUX”,“browserName”:“Android”,“platformVersion”:“4.2.2”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“app”:“C:\testing apks\checkers_android_20150921_v2.2.35.apk”,“platformName”:“Android”,“deviceName”:“Gravy train(GT-I9190)”,“newCommandTimeout”:“100”,“platformVersion”:“4.2.2”},“app”:“C:\testing apks\checkers_android_20150921_v2.2.35.apk”,“platformName”:“Android”,“deviceName”:“20cbcdd4”,“newCommandTimeout”:“100”},“sessionId”:“704a9f7c-00c2-4846-bb88-a4d138a8b86a”}
info: → POST /wd/hub/session/704a9f7c-00c2-4846-bb88-a4d138a8b86a/element {“using”:“xpath”,“value”:“//android.widget.Button[@id=‘Browse’”}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: [“find”,{“strategy”:“xpath”,“selector”:“//android.widget.Button[@id=‘Browse’”,“context”:“”,“multiple”:false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:“//android.widget.Button[@id=‘Browse’”,“context”:“”,“multiple”:false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding //android.widget.Button[@id=‘Browse’ using XPATH with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Returning result: {“value”:"javax.xml.transform.TransformerException: Expected ], but found: ",“status”:32}
info: [debug] Condition unmet after 67ms. Timing out.
info: [debug] Responding to client with error: {“status”:32,“value”:{“message”:“Argument was an invalid selector (e.g. XPath/CSS).”,“origValue”:"javax.xml.transform.TransformerException: Expected ], but found: "},“sessionId”:“704a9f7c-00c2-4846-bb88-a4d138a8b86a”}
info: ← POST /wd/hub/session/704a9f7c-00c2-4846-bb88-a4d138a8b86a/element 500 70.415 ms - 217

Looks like appium could not find the above element. Does this show up in arc or the inspector?

HI there

In my UI Automator viewer the details are as follows. Not all the Node Details are filled in. I tried using the findbytext but dont have that option in webdriver or androiddriver. How can i with limited details impliment this?

Ah looks like a syntax error (missing bracket) You have this:
WebElement browse = driver.findElement(By.xpath("//android.widget.Button[@id=‘Browse’"));
browse.click();

It should be this:

WebElement browse = driver.findElement(By.xpath("//android.widget.Button[@id=‘Browse’]"));
browse.click();

good luck!

HI thanks for the help changed my code a bit. working now. inputing a wait exception also helped.

I am having a issue while running automation script
I am getting org.openqa.selenium.InvalidSelectorException: javax.xml.transform.TransformerException: error

Sample code:

 //driver.findElementByAccessibilityId("RootTopLeftMenuButton");
 //driver.findElement(By.xpath("//android.view.ViewGroup[@accessibility id=RootTopLeftMenuButton]")).click();
//driver.findElement(By.xpath("//android.view.ViewGroup[@content-desc=\'RootTopLeftMenuButton\']")).click();
 driver.findElement(By.xpath("//*[@accessibility id=\'RootTopLeftMenuButton\']")).click();
 // driver.findElement(By.id("RootTopLeftMenuButton")).click();

Find the appium logs

[Appium] Welcome to Appium v1.9.0
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"appPackage":"com.rt.pinprickeffect.meditation.staging","appActivity":"com.rt.pinprickeffect.meditation.MainActivity","browserName":"","platformName":"Android","deviceName":"Honor 9Lite","version":8}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"appPackage":"com.rt.pinprickeffect.meditation.staging","appActivity":"com.rt.pinprickeffect.meditation.MainActivity","browserName":"","platformName":"Android","deviceName":"Honor 9Lite","version":8},null,null]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1538120223739 (13:07:03 GMT+0530 (India Standard Time))
[Appium] Creating new AndroidDriver (v3.7.0) session
[Appium] Capabilities:
[Appium]   appPackage: com.rt.pinprickeffect.meditation.staging
[Appium]   appActivity: com.rt.pinprickeffect.meditation.MainActivity
[Appium]   browserName:
[Appium]   platformName: Android
[Appium]   deviceName: Honor 9Lite
[Appium]   version: 8
[debug] [BaseDriver] Creating session with MJSONWP desired capabilities: {"appPackage":"com.rt.pinpr...
[BaseDriver] The following capabilities were provided, but are not recognized by appium: version.
[BaseDriver] Session created with session id: 4623d7a2-01fe-459c-a886-878ac21fa192
[AndroidDriver] Java version is: 1.8.0_141
[ADB] Checking whether adb is present
[ADB] Found 5 'build-tools' folders under 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows' (newest first):
[ADB]     C:/Users/Mahadev/AndriodSoftwere/android-sdk-windows/build-tools/28.0.3
[ADB]     C:/Users/Mahadev/AndriodSoftwere/android-sdk-windows/build-tools/26.0.2
[ADB]     C:/Users/Mahadev/AndriodSoftwere/android-sdk-windows/build-tools/26.0.0
[ADB]     C:/Users/Mahadev/AndriodSoftwere/android-sdk-windows/build-tools/25.0.2
[ADB]     C:/Users/Mahadev/AndriodSoftwere/android-sdk-windows/build-tools/23.0.1
[ADB] Using adb.exe from C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\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
[debug] [ADB] Setting device id to emulator-5554
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell getprop ro.build.version.sdk'
[debug] [ADB] Current device property 'ro.build.version.sdk': 24
[debug] [ADB] Device API level: 24
[AndroidDriver] Consider setting 'automationName' capability to 'uiautomator2' on Android >= 6, since UIAutomator framework is not maintained anymore by the OS vendor.
[AndroidDriver] App file was not listed, instead we're going to run com.rt.pinprickeffect.meditation.staging directly on the device
[debug] [AndroidDriver] Checking whether package is present on the device
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell pm list packages com.rt.pinprickeffect.meditation.staging'
[AndroidDriver] Starting Android session
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 wait-for-device'
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell echo ping'
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -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] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell dumpsys package io.appium.settings'
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\build-tools\28.0.3\aapt.exe
[debug] [ADB] The installed 'io.appium.settings' package does not require upgrade ('2.3.0' >= '2.3.0')
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell ps'
[debug] [AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
[debug] [ADB] Device API level: 24
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell appops set io.appium.settings android\:mock_location allow'
[AndroidDriver] setDeviceLanguageCountry requires language or country.
[AndroidDriver] Got language: 'null' and country: 'null'
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Getting install status for io.appium.unlock
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell pm list packages io.appium.unlock'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.unlock'
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell dumpsys package io.appium.unlock'
[debug] [ADB] The installed 'io.appium.unlock' package does not require upgrade ('2.0.0' >= '2.0.0')
[ADB] Getting device platform version
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell getprop ro.build.version.release'
[debug] [ADB] Current device property 'ro.build.version.release': 7.0
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell wm size'
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -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] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell getprop ro.product.manufacturer'
[debug] [ADB] Current device property 'ro.product.manufacturer': Google
[AndroidDriver] No app sent in, not parsing package/activity
[debug] [AndroidDriver] No app capability. Assuming it is already on the device
[debug] [ADB] Getting install status for com.rt.pinprickeffect.meditation.staging
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell pm list packages com.rt.pinprickeffect.meditation.staging'
[debug] [ADB] App is installed
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am force-stop com.rt.pinprickeffect.meditation.staging'
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell pm clear com.rt.pinprickeffect.meditation.staging'
[debug] [AndroidDriver] Performed fast reset on the installed 'com.rt.pinprickeffect.meditation.staging' application (stop and clear)
[debug] [AndroidBootstrap] Watching for bootstrap disconnect
[debug] [ADB] Forwarding system: 4724 to device: 4724
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -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\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 push C\:\\Users\\Mahadev\\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] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -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","com.rt.pinprickeffect.meditation.staging","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[debug] [UiAutomator] Moving to state 'online'
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Loading json...
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] Android bootstrap socket is now connected
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell dumpsys window'
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[AndroidDriver] Screen already unlocked, doing nothing
[debug] [ADB] Device API level: 24
[debug] [ADB] Running 'C:\Users\Mahadev\AndriodSoftwere\android-sdk-windows\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am start -W -n com.rt.pinprickeffect.meditation.staging/com.rt.pinprickeffect.meditation.MainActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000'
[Appium] New AndroidDriver session created successfully, session 4623d7a2-01fe-459c-a886-878ac21fa192 added to master session list
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1538120229793 (13:07:09 GMT+0530 (India Standard 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":{"appPackage":"com.rt.pinprickeffect.meditation.staging","appActivity":"com.rt.pinprickeffect.meditation.MainActivity","browserName":"","platformName":"Android","deviceName":"Honor 9Lite","version":8},"appPackage":"com.rt.pinprickeffect.meditation.staging","appActivity":"com.rt.pinprickeffect.meditation.MainActivity","browserName":"","platformName":"Android","deviceName":"emulator-5554","version":8,"deviceUDID":"emulator-5554","platformVersion":"7.0","deviceScreenSize":"1440x2560","deviceModel":"Android SDK built for x86","deviceManufacturer":"Google"}
[HTTP] <-- POST /wd/hub/session 200 6063 ms - 835
[HTTP]
[HTTP] --> POST /wd/hub/session/4623d7a2-01fe-459c-a886-878ac21fa192/timeouts
[HTTP] {"type":"implicit","ms":30000}
[debug] [MJSONWP] Calling AppiumDriver.timeouts() with args: ["implicit",30000,null,null,null,"4623d7a2-01fe-459c-a886-878ac21fa192"]
[debug] [BaseDriver] MJSONWP timeout arguments: {"type":"implicit","ms":30000}}
[debug] [BaseDriver] Set implicit wait to 30000ms
[debug] [MJSONWP] Responding to client with driver.timeouts() result: null
[HTTP] <-- POST /wd/hub/session/4623d7a2-01fe-459c-a886-878ac21fa192/timeouts 200 21 ms - 76
[HTTP]
[HTTP] --> POST /wd/hub/session/4623d7a2-01fe-459c-a886-878ac21fa192/element
[HTTP] {"using":"xpath","value":"//*[@accessibility id='RootTopLeftMenuButton']"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["xpath","//*[@accessibility id='RootTopLeftMenuButton']","4623d7a2-01fe-459c-a886-878ac21fa192"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 30000 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[@accessibility id='RootTopLeftMenuButton']","context":"","multiple":false}}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Matched JSONWP error code 32 to InvalidSelectorError
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[@accessibility id='RootTopLeftMenuButton']","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//*[@accessibility id='RootTopLeftMenuButton']' using 'XPATH' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":32,"value":"javax.xml.transform.TransformerException: Expected ], but found: id"}
[MJSONWP] Encountered internal error running command: InvalidSelectorError: javax.xml.transform.TransformerException: Expected ], but found: id
[MJSONWP]     at errorFromMJSONWPStatusCode (C:\Users\Mahadev\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:784:12)
[MJSONWP]     at Socket.<anonymous> (C:\Users\Mahadev\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-bootstrap\lib\bootstrap.js:139:18)
[MJSONWP]     at emitOne (events.js:116:13)
[MJSONWP]     at Socket.emit (events.js:211:7)
[MJSONWP]     at addChunk (_stream_readable.js:263:12)
[MJSONWP]     at readableAddChunk (_stream_readable.js:246:13)
[MJSONWP]     at Socket.Readable.push (_stream_readable.js:208:10)
[MJSONWP]     at TCP.onread (net.js:594:20)