Failed to locate element. Clearing Accessibility cache and retrying

Hi,

I am new to Appium. I am trying to run the script to touch the login button of an app. Appium server logs indicates that its not able to find the button, even though its present in the screen. I have increased the timeout to 500000 just for troubleshooting.

Here is the code snippet and Appium server logs.

Code snippet:

import java.io.File;

import java.net.MalformedURLException;

import java.net.URL;

import org.junit.Test;

import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;

import io.appium.java_client.remote.MobileCapabilityType;

import io.appium.java_client.remote.MobilePlatform;

public class AndroidConnect {

@Test

public void test() throws MalformedURLException {

File src=new File(“src”);

File app_path=new File(src,“book_my_show.apk”);

DesiredCapabilities dc =new DesiredCapabilities();

dc.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);

dc.setCapability(MobileCapabilityType.DEVICE_NAME, “Android Device”);

dc.setCapability(MobileCapabilityType.UDID, “51900LMA01”);

dc.setCapability(MobileCapabilityType.APP, app_path.getAbsolutePath());

AndroidDriver ad=new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), dc);

dc.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, “500000”);

ad.findElementById(“com.bt.bms:id/btnLogin”).click();;

}

}

Appium server:

[HTTP] --> POST /wd/hub/session {“desiredCapabilities”:{“app”:"/Users/gj/Documents/workspace/Connectvity/src/book_my_show.apk",“platformName”:“Android”,“udid”:“51900LMA01”,“deviceName”:“Android Device”}}

[MJSONWP] Calling AppiumDriver.createSession() with args: [{“app”:"/Users/gj/Docume…

[Appium] Creating new AndroidDriver session

[Appium] Capabilities:

[Appium] app: ‘/Users/gj/Documents/workspace/Connectvity/src/book_my_show.apk’

[Appium] platformName: ‘Android’

[Appium] udid: ‘51900LMA01’

[Appium] deviceName: ‘Android Device’

[Appium] platformVersion: ‘4.4’

[Appium] automationName: ‘Appium’

[BaseDriver] Session created with session id: 44ebccfa-138a-4344-a1ed-e2aafefe99f6

[debug] [AndroidDriver] Getting Java version

[AndroidDriver] Java version is: 1.8.0_45

[ADB] Checking whether adb is present

[ADB] Using adb from /Users/gj/Library/Android/sdk/platform-tools/adb

[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: 51900LMA01

[ADB] Checking whether adb is present

[ADB] Using adb from /Users/gj/Library/Android/sdk/platform-tools/adb

[debug] [ADB] Setting device id to 51900LMA01

[BaseDriver] Using local app ‘/Users/gj/Documents/workspace/Connectvity/src/book_my_show.apk’

[debug] [AndroidDriver] Checking whether app is actually present

[AndroidDriver] Starting Android session

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“wait-for-device”]

[debug] [ADB] Getting connected devices…

[debug] [ADB] 1 device(s) connected

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“echo”,“ping”]

[debug] [Logcat] Starting logcat capture

[debug] [AndroidDriver] Pushing settings apk to device…

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“install”,"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/io.appium.settings/bin/settings_apk-debug.apk"]

[debug] [AndroidDriver] Pushing unlock helper app to device…

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“install”,"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-unlock/bin/unlock_apk-debug.apk"]

[ADB] Getting device platform version

[debug] [ADB] Getting connected devices…

[debug] [ADB] 1 device(s) connected

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“getprop”,“ro.build.version.release”]

[debug] [ADB] Getting connected devices…

[debug] [ADB] 1 device(s) connected

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“dumpsys”,“window”]

[AndroidDriver] Screen already unlocked, doing nothing

[debug] [AndroidDriver] Parsing package and activity from app manifest

[ADB] Checking whether aapt is present

[ADB] Using aapt from /Users/gj/Library/Android/sdk/build-tools/23.0.2/aapt

[ADB] Extracting package and launch activity from manifest

[debug] [ADB] badging package: com.bt.bms

[debug] [ADB] badging act: com.bt.bms.activities.SplashActivity

[debug] [AndroidDriver] Parsed package and activity are: com.bt.bms/com.bt.bms.activities.SplashActivity

[AndroidDriver] Remote apk path is /data/local/tmp/ddfffcfcd8da80de903e7d30c337575c.apk

[debug] [ADB] Getting connected devices…

[debug] [ADB] 1 device(s) connected

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“ls”,"/data/local/tmp/ddfffcfcd8da80de903e7d30c337575c.apk"]

[debug] [AndroidDriver] Checking if app is installed

[debug] [ADB] Getting install status for com.bt.bms

[debug] [ADB] Getting connected devices…

[debug] [ADB] 1 device(s) connected

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“getprop”,“ro.build.version.sdk”]

[debug] [ADB] Device API level: 22

[debug] [ADB] Getting connected devices…

[debug] [ADB] 1 device(s) connected

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“pm”,“list”,“packages”,"-3",“com.bt.bms”]

[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 /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“am”,“force-stop”,“com.bt.bms”]

[debug] [ADB] Getting connected devices…

[debug] [ADB] 1 device(s) connected

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“pm”,“clear”,“com.bt.bms”]

[debug] [AndroidDriver] Extracting strings from apk /Users/gj/Documents/workspace/Connectvity/src/book_my_show.apk null /var/folders/x0/xz8s_xtx5f3_x8my_1_9_pddm3qx35/T/com.bt.bms

[debug] [ADB] Extracting strings for language: default

[debug] [ADB] Device API level: 22

[debug] [ADB] Getting connected devices…

[debug] [ADB] 1 device(s) connected

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“getprop”,“persist.sys.language”]

[debug] [ADB] Current device property ‘persist.sys.language’: en

[debug] [ADB] No strings.xml for language ‘en’, getting default strings.xml

[debug] [ADB] Reading strings from converted strings.json

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“push”,"/var/folders/x0/xz8s_xtx5f3_x8my_1_9_pddm3qx35/T/com.bt.bms/strings.json","/data/local/tmp"]

[debug] [AndroidBootstrap] Watching for bootstrap disconnect

[debug] [ADB] Forwarding system: 4724 to device: 4724

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“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 /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“push”,"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/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 /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“ps”,“uiautomator”]

[ADB] No uiautomator process found to kill, continuing…

[debug] [UiAutomator] Starting UIAutomator

[debug] [ADB] Creating ADB subprocess with args: -P, 5037, -s, 51900LMA01, shell, uiautomator, runtest, AppiumBootstrap.jar, -c, io.appium.android.bootstrap.Bootstrap, -e, pkg, com.bt.bms, -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] Device API level: 22

[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 /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“am”,“start”,"-n",“com.bt.bms/com.bt.bms.activities.SplashActivity”,"-S","-a",“android.intent.action.MAIN”,"-c",“android.intent.category.LAUNCHER”,"-f",“0x10200000”]

[debug] [ADB] Waiting for pkg: ‘com.bt.bms’ and activity: ‘com.bt.bms.activities.SplashActivity’ to be focused

[debug] [ADB] Possible activities, to be checked: com.bt.bms.activities.SplashActivity, .activities.SplashActivity, .com.bt.bms.activities.SplashActivity

[debug] [ADB] Getting focused package and activity

[debug] [ADB] Getting connected devices…

[debug] [ADB] 1 device(s) connected

[debug] [ADB] Running /Users/gj/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s",“51900LMA01”,“shell”,“dumpsys”,“window”,“windows”]

[debug] [ADB] Found package: ‘com.bt.bms’ and activity: ‘.activities.SplashActivity’

[Appium] New AndroidDriver session created successfully, session 44ebccfa-138a-4344-a1ed-e2aafefe99f6 added to master session list

[MJSONWP] Responding to client with driver.createSession() result: {“platform”:“LINUX”,"webSto…

[HTTP] <-- POST /wd/hub/session 200 5851 ms - 863

[HTTP] --> POST /wd/hub/session/44ebccfa-138a-4344-a1ed-e2aafefe99f6/element {“using”:“id”,“value”:“com.bt.bms:id/btnLogin”}

[MJSONWP] Calling AppiumDriver.findElement() with args: [“id”,"com.bt.bms:id/btnLog…

[debug] [BaseDriver] Waiting up to 0 ms for condition

[debug] [AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“id”,“selector”:“com.bt.bms:id/btnLogin”,“context”:"",“multiple”:false}}

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“id”,“selector”:“com.bt.bms:id/btnLogin”,“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 ‘com.bt.bms:id/btnLogin’ using ‘ID’ with the contextId: ‘’ multiple: false

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.bt.bms:id/btnLogin]

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘com.bt.bms:id/btnLogin’ using ‘ID’ with the contextId: ‘’ multiple: false

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.bt.bms:id/btnLogin]

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:7,“value”:“No element found”}

[debug] [AndroidBootstrap] Received command result from bootstrap

[HTTP] <-- POST /wd/hub/session/44ebccfa-138a-4344-a1ed-e2aafefe99f6/element 500 895 ms - 164