# Android emulator xpath findElements() sometimes hanging for \> 10 minutes

**URL:** <https://discuss.appium.io/t/android-emulator-xpath-findelements-sometimes-hanging-for-10-minutes/14688>\
**Category:** Issues/Bugs\
**Created:** [February 8, 2017, 5:35pm UTC](https://discuss.appium.io/t/android-emulator-xpath-findelements-sometimes-hanging-for-10-minutes/14688 "2017-02-08T17:35:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bennid](https://discuss.appium.io/user_avatar/discuss.appium.io/bennid/32/3145_2.png) [@bennid](https://discuss.appium.io/u/bennid)\
**Post date:** [February 8, 2017, 5:35pm UTC](https://discuss.appium.io/t/android-emulator-xpath-findelements-sometimes-hanging-for-10-minutes/14688/1 "2017-02-08T17:35:06Z")

</div>

Is anyone aware of why this would hang up? It’s running perfectly fine one one machine, but hanging on another causing timeouts and eventually jenkins to just abort the job. The element that is being searched for is actually not on the screen, but I need to look for it in order to determine what to do next.

> 2017-02-08 16:56:52:576 - [HTTP] → POST /wd/hub/session/75d17b2f-9173-41b0-8c6f-6ae4e50ee5e5/elements {“using”:“xpath”,“value”:“[//android.widget.EditText](https://android.widget.EditText)[contains(@resource-id,‘com.xxxxx.prerelease:id/query’) and @text=‘Foobar’]”}  
> 2017-02-08 16:56:52:578 - [debug] [MJSONWP] Calling AppiumDriver.findElements() with args: [“xpath”,“[//android.widget.EditText](https://android.widget.EditText)[contains(@resource-id,‘com.xxxxx.prerelease:id/query’) and @text=‘Foobar’]”,“75d17b2f-9173-41b0-8c6f-6ae4e50ee5e5”]  
> 2017-02-08 16:56:52:580 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator  
> 2017-02-08 16:56:52:581 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator  
> 2017-02-08 16:56:52:581 - [debug] [BaseDriver] Waiting up to 0 ms for condition  
> 2017-02-08 16:56:52:582 - [debug] [AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:“[//android.widget.EditText](https://android.widget.EditText)[contains(@resource-id,‘com.xxxxx.prerelease:id/query’) and @text=‘Foobar’]”,“context”:“”,“multiple”:true}}  
> 2017-02-08 16:56:52:691 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:“[//android.widget.EditText](https://android.widget.EditText)[contains(@resource-id,‘com.xxxxx.prerelease:id/query’) and @text=‘Foobar’]”,“context”:“”,“multiple”:true}}  
> 2017-02-08 16:56:52:691 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION  
> 2017-02-08 16:56:52:692 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find  
> 2017-02-08 16:56:52:693 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘[//android.widget.EditText](https://android.widget.EditText)[contains(@resource-id,‘com.xxxxx.prerelease:id/query’) and @text=‘Foobar’]’ using ‘XPATH’ with the contextId: ‘’ multiple: true  
> 2017-02-08 16:56:53:415 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.  
> 2017-02-08 16:56:53:416 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘[//android.widget.EditText](https://android.widget.EditText)[contains(@resource-id,‘com.xxxxx.prerelease:id/query’) and @text=‘Foobar’]’ using ‘XPATH’ with the contextId: ‘’ multiple: true  
> 2017-02-08 17:06:52:567 - [HTTP] ← POST /wd/hub/session/75d17b2f-9173-41b0-8c6f-6ae4e50ee5e5/elements - - ms - -

I have no clue what’s going on between those last 2 lines either…

Currently using

- Appium server 1.6.3
- Appium java client 5.0.0-BETA1 (tried BETA2 as well)
- Emulator android-sdk-macosx-r24.4.1

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [February 8, 2017, 9:27pm UTC](https://discuss.appium.io/t/android-emulator-xpath-findelements-sometimes-hanging-for-10-minutes/14688/2 "2017-02-08T21:27:43Z")

</div>

forget about xpath. use it only as last resort. it is always 100 times slower then any other method.  
try something like:

```
    driver.findElement(MobileBy.AndroidUIAutomator(
            "new UiSelector().resourceId(\"com.xxxxx.prerelease:id/query\")." +
                    "childSelector(new UiSelector().text(\""+text+"\");\"))"));

```

or

```
List<WebElements> result = driver.findElements(MobileBy.Id("com.xxxxx.prerelease:id/query"));
foreach (WebElement el : result) {
  if (el.getText().equals("sometext")) {
     // do somehting
     break;
  }
}
```

---

<div class="post-metadata">

**Author:** ![bennid](https://discuss.appium.io/user_avatar/discuss.appium.io/bennid/32/3145_2.png) [@bennid](https://discuss.appium.io/u/bennid)\
**Post date:** [February 8, 2017, 9:39pm UTC](https://discuss.appium.io/t/android-emulator-xpath-findelements-sometimes-hanging-for-10-minutes/14688/3 "2017-02-08T21:39:28Z")

</div>

Thanks, was on my way there as well 😉 Just need to build up a good UiSelector helper so I’m not just using strings.

-Ben
