XPath broken for Android?


  • Appium v1.2.1 (also tried on v1.2.2 as well) GUI
  • MacOS 10.9.5
  • Android 4.4.2

I am trying to use XPath to access elements in an Android application but get the following error in the Appium log:

info: → POST /wd/hub/session/873975fe-2358-4ce6-aec4-74d10f9166f9/elements {“using”:“xpath”,“value”:“//android.view.View[2]/android.widget.FrameLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]”}

info: [debug] Pushing command to appium work queue: [“find”,{“strategy”:“xpath”,“selector”:“//android.view.View[2]/android.widget.FrameLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]”,“context”:“”,“multiple”:true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:“//android.view.View[2]/android.widget.FrameLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]”,“context”:“”,“multiple”:true}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding //android.view.View[2]/android.widget.FrameLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1] using XPATH with the contextId: multiple: true
info: [debug] [UIAUTOMATOR STDOUT] java.io.FileNotFoundException: /data/local/tmp/dump.xml: open failed: ENOENT (No such file or directory)
info: [debug] [UIAUTOMATOR STDOUT] at
info: [debug] Responding to client with error: {“status”:13,“value”:{“message”:“An unknown server-side error occurred while processing the command.”,“origValue”:“Failed to Dump Window Hierarchy”},“sessionId”:“873975fe-2358-4ce6-aec4-74d10f9166f9”}
info: ← POST /wd/hub/session/873975fe-2358-4ce6-aec4-74d10f9166f9/elements 500 10.430 ms - 200

I received the following error in the Terminal:

Error: [elements(“xpath”,“//android.view.View[2]/android.widget.FrameLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]”)] Error response status: 13, , UnknownError - An unknown server-side error occurred while processing the command. Selenium error: An unknown server-side error occurred while processing the command.
at exports.newError (/Users/myName/Repos/myProject/node_modules/wd/lib/utils.js:139:13)
at /Users/myName/Repos/myProject/node_modules/wd/lib/callbacks.js:75:19
at /Users/myName/Repos/myProject/node_modules/wd/lib/webdriver.js:169:5
at Request._callback (/Users/myName/Repos/myProject/node_modules/wd/lib/http-utils.js:84:7)
at Request.self.callback (/Users/myName/Repos/myProject/node_modules/wd/node_modules/request/request.js:236:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request. (/Users/myName/Repos/myProject/node_modules/wd/node_modules/request/request.js:1142:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage. (/Users/myName/Repos/myProject/node_modules/wd/node_modules/request/request.js:1096:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:919:16
at process._tickCallback (node.js:419:13)

Is there a known issue regarding this? Please advise how to resolve.


What context are you in?? Webview or native???

Native app

As the following topic mentions Appium android webviews documentation/xpath issues
xpath in native context has some issues and still not stable. I recommend using ID or Class name as a workaround until it’s more stable to depend on it.

I have tried using ID and Class, but it isn’t unique in all situations. In many cases, elements have the same ID and Class, such as those within a list view on Android. Has any workaround been found for such situations?

You can find elements with these two locators:

  • UIAutomator by using method findElementByAndroidUIAutomator in Appium client.
  • Name

Another possible solution is to ask your developers to use Static IDs for the elements … it’s a best practice and they should follow it anyway :smile: