Appium Find element issues, work sometimes and fails again


#1

Hi All,

I am facing issue while trying to locate an element in a list view.
Sometime it works and it fails in the next iteration.
I have used “id” as a locator and as well as xpath in next iteration. But it fails intermittently in both cases.
Much appreciate help.

[debug] [MJSONWP] Calling AppiumDriver.getCurrentContext() with args: [“b53004b0-b454-493a-8995-698d3aa5a6ba”]
[debug] [MJSONWP] Responding to client with driver.getCurrentContext() result: “NATIVE_APP”
[HTTP] <-- GET /wd/hub/session/b53004b0-b454-493a-8995-698d3aa5a6ba/context 200 1 ms - 84
[HTTP] --> POST /wd/hub/session/b53004b0-b454-493a-8995-698d3aa5a6ba/elements {“using”:“id”,“value”:“signal_strength_id”}
[debug] [MJSONWP] Calling AppiumDriver.findElements() with args: [“id”,“signal_strength_id”,“b53004b0-b454-493a-8995-698d3aa5a6ba”]
[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”:“id”,“selector”:“signal_strength_id”,“context”:"",“multiple”:true}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“id”,“selector”:“signal_strength_id”,“context”:"",“multiple”:true}}
[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 ‘signal_strength_id’ using ‘ID’ with the contextId: ‘’ multiple: true
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=com.dewalt.toolconnectv2:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=com.dewalt.toolconnectv2:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.dewalt.toolconnectv2:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=android:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=android:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=android:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[DESCRIPTION=signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[DESCRIPTION=signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[DESCRIPTION=signal_strength_id, INSTANCE=0]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘signal_strength_id’ using ‘ID’ with the contextId: ‘’ multiple: true
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=com.dewalt.toolconnectv2:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=com.dewalt.toolconnectv2:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.dewalt.toolconnectv2:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=android:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=android:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=android:id/signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[DESCRIPTION=signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[DESCRIPTION=signal_strength_id]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[DESCRIPTION=signal_strength_id, INSTANCE=0]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:[]}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.findElements() result: []
[HTTP] <-- POST /wd/hub/session/b53004b0-b454-493a-8995-698d3aa5a6ba/elements 200 37393 ms - 74
[HTTP] --> POST /wd/hub/session/b53004b0-b454-493a-8995-698d3aa5a6ba/timeouts {“type”:“implicit”,“ms”:1000}
[debug] [MJSONWP] Calling AppiumDriver.timeouts() with args: [“implicit”,1000,“b53004b0-b454-493a-8995-698d3aa5a6ba”]
[debug] [BaseDriver] Set implicit wait to 1000ms
[debug] [MJSONWP] Responding to client with driver.timeouts() result: null
[HTTP] <-- POST /wd/hub/session/b53004b0-b454-493a-8995-698d3aa5a6ba/timeouts 200 2 ms - 76
[HTTP] --> POST /wd/hub/session/b53004b0-b454-493a-8995-698d3aa5a6ba/timeouts {“type”:“implicit”,“ms”:0}
[debug] [MJSONWP] Calling AppiumDriver.timeouts() with args: [“implicit”,0,“b53004b0-b454-493a-8995-698d3aa5a6ba”]
[debug] [BaseDriver] Set implicit wait to 0ms
[debug] [MJSONWP] Responding to client with driver.timeouts() result: null
[HTTP] <-- POST /wd/hub/session/b53004b0-b454-493a-8995-698d3aa5a6ba/timeouts 200 2 ms - 76
[HTTP] --> GET /wd/hub/session/b53004b0-b454-493a-8995-698d3aa5a6ba/context {}
[debug] [MJSONWP] Calling AppiumDriver.getCurrentContext() with args: [“b53004b0-b454-493a-8995-698d3aa5a6ba”]
[debug] [MJSONWP] Responding to client with driver.getCurrentContext() result: “NATIVE_APP”
[HTTP] <-- GET /wd/hub/session/b53004b0-b454-493a-8995-698d3aa5a6ba/context 200 1 ms - 84
[HTTP] --> POST /wd/hub/session/b53004b0-b454-493a-8995-698d3aa5a6ba/elements {“using”:“xpath”,“value”:"//android.widget.ListView/android.widget.FrameLayout[1]/android.widget.RelativeLayout/android.widget.ImageView[4]"}
[debug] [MJSONWP] Calling AppiumDriver.findElements() with args: [“xpath”,"//android.widget.ListView/android.widget.FrameLayout[1]/android.widget.RelativeLayout/android.widget.ImageView[4]","b53004b0-b454-493a-8995-698d3aa5a6ba"]
[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”:"//android.widget.ListView/android.widget.FrameLayout[1]/android.widget.RelativeLayout/android.widget.ImageView[4]",“context”:"","multiple":true}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:"//android.widget.ListView/android.widget.FrameLayout[1]/android.widget.RelativeLayout/android.widget.ImageView[4]",“context”:"","multiple":true}}
[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 ‘//android.widget.ListView/android.widget.FrameLayout[1]/android.widget.RelativeLayout/android.widget.ImageView[4]’ using ‘XPATH’ with the contextId: ‘’ multiple: true


#2

Share your desired capabilities here and is the element viewable on screen or is it visible after a scroll?


#3

{
“platformName”: “Android”,
“deviceName”: “Samsung S6”,
“app”: “/Users/LKG0716/LALIT/Projects/ToolConnect/Automation/Apps/app-debug_124.apk”,
“platformVersion”: “8.0”,
“noReset”: true,
“udid”: “FA71A0303273”
}

Yes, the element is viewable on screen. I do not need to do any scroll.


#4

Can you add this to your desired capabilities since your device os is higher than 7.0

automationName: UiAutomator2

#5

I have added the “automationName: UiAutomator2” now, but started getting another error.

Initializing the driver
Exception in initializing Android Driver : An unknown server-side error occurred while processing the command. Original error: JAVA_HOME is not set currently. Please set JAVA_HOME. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7.88 seconds

I have set the java_home environment variable in eclipse and also in bash_profile file.


#6


#7

just to confirm this should be

"automationName": "UiAutomator2",

For JAVA_HOME I have this in my .bash_profile

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=${PATH}$JAVA_HOME/bin

#8

I have the same capabilities as you mentioned.

caps.setCapability(“automationName”, “UiAutomator2”);

[email protected]:~$ cat .bash_profile
export ANDROID_HOME=/Users/LKG0716/Library/Android/sdk
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$JAVA_HOME/bin


#9
npm install -g appium-doctor

then run the below command in terminal. It will list out all the errors, fix them all.

appium-doctor

#10


#11

appium-doctor does not have java_home problem. But eclipse still shows the same issue


#12

Thanks much Venkatesh, It works now. Not sure the reason, but I had to close my android studio which was running.
Restarting eclipse didn’t help.


#13

Hi lalit same switch problem is there i am add the dc.setCapability(“automationName”, “UiAutomator2”);

i run the script appum logs error will comeing on below


#14


#15

The log shows that you should include platformName capability, attached your screenshot with error highlighted.


#16

i am mention platform name capability in below
dc = new DesiredCapabilities();;
//dc.setCapability(“deviceName”, “F9AZCY17X014”);
//dc.setCapability(“platformVersion”, “5.0.2”);
dc.setCapability(“deviceName”, “emulator-5554”);
dc.setCapability(“platformVersion”, “7.0”);
dc.setCapability(“platformName”, “Android”);
dc.setCapability(“automationName”, “UiAutomator2”);
dc.setCapability(“noReset”, “True”);
dc.setCapability(“fullReset”, “False”);
dc.setCapability(“appPackage”, “com.livenation.mobile.android.na”);
dc.setCapability(“appActivity”, “com.livenation.mobile.android.na.MainActivity”);


#17

it will be comeing on error in venkatesh


#18

I am getting issues on finding elements in iOS 11.
For example, in the attached screenshot, I want to find element for the tool name, which is ‘BAT’ now. This may change and so will be the xpath. The accessibility id added by the developer does not work as well.


#19

Hi Lalit, I too faced a similar problem. The best solution here is to ask your development team to implement generic accessibility id’s for these kind of fields.

For example in your case, they can name it tool_name. Once its implemented you can do

self.driver.find_element_by_id('tool_name')

Fo now you can select it using xpath
Sample:

//*/XCUIElementTypeTable/XCUIElementTypeCell[2]/XCUIElementTypeStaticText[2]

#20

The development team had added accessibility id for some elements. But I could see that id in appium gui.

And the xpath, I am seeing from appium gui is like below:
//XCUIElementTypeStaticText[@name=“BAT”]
I do not see a tree like structured xpath.