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

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[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[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[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[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[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[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

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;
  }
}

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

-Ben