Appium 1.6+ issue with findbyAndroidUIAutomator

Hi,
I am facing issues in finding elements using uiautomator.

DesiredCapability - automationName is set to uiautomator2

Element to find: new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className(“android.widget.TextView”),“Log off”)

I could see the screen is scrolling but it just stops and doesnt return the element, instead it throws ESOCKETTIMEOUT error.

Below is the appium log:

[debug] [MJSONWP] Responding to client with driver.findElements() result: []
[HTTP] <-- POST /wd/hub/session/0f1dc2f8-f219-4170-9ffe-7579e07e7883/elements 200 147 ms - 74
[HTTP] --> POST /wd/hub/session/0f1dc2f8-f219-4170-9ffe-7579e07e7883/elements {“using”:"-android uiautomator",“value”:“new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className(“android.widget.TextView”),“Log off”)”}
[debug] [MJSONWP] Calling AppiumDriver.findElements() with args: ["-android uiautomator",“new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className(“android.widget.TextView”),“Log off”)”,“0f1dc2f8-f219-4170-9ffe-7579e07e7883”]
[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] [JSONWP Proxy] Proxying [POST /elements] to [POST http://localhost:8202/wd/hub/session/6f00f694-4cbf-4cc1-a3c8-61b7ad81a0ac/elements] with body: {“strategy”:"-android uiautomator",“selector”:“new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className(“android.widget.TextView”),“Log off”)”,“context”:"",“multiple”:true}
[MJSONWP] Encountered internal error running command: ProxyRequestError: Could not proxy command to remote server. Original error: Error: ESOCKETTIMEDOUT
at JWProxy.proxy$ (…/…/…/lib/jsonwp-proxy/proxy.js:144:13)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session/0f1dc2f8-f219-4170-9ffe-7579e07e7883/elements 500 240021 ms - 251

Is anyone facing similar issue? Kindly request to provide suggestions.

Thanks,
Pavithra

I’ve gotten this error when there is animation in my app. This sounds somewhat similar. I’ve gotten around it by adding an explicit wait of a second or two before trying to interact (like clicking) with the element. It’s kind of hacky but it works. YMMV.

Need to add wait after each scroll as this would take some time for loading, better you could add fluent wait here to poll for an element to appear

Hi, Thanks for the reply ! But in my case, there is no animation in the screen and element is loaded immediately after the scroll. I already have enough wait and using fluent wait with polling. I tried for another elements where I find using uiautomator and in all the places appium throws the same error if it tries to find using uiautomator2.
Note: It is not failing with tap or click, its failing to find the element.

Is findbyuaituomator working for you with automationName:uiautomator2 ?

Hi,
Did anyone got it working for findElementByAndroidUIAutomator with uiautomator2 ?
I still face same issue and getting- ESOCKETTIMEOUT error.

Appium Version: 1.6.5 (installed via npm)
Applium java client - 5.0.0-BETA8
capabilities.setCapability(“automationName”, “uiautomator2”); - set the capability in the code

Android Version - 7.0

Find Element code:

String args = “new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className(“android.widget.TextView”),“Log off”)”;
try {
WebDriverWait wait = new WebDriverWait(driver, 5, 100);
wait.ignoring(org.openqa.selenium.NoSuchElementException.class);
wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AndroidUIAutomator(args)));
AndroidElement element = (AndroidElement) driver.findElementByAndroidUIAutomator(args);
Main.logMessage(“AndroidElement for " + locator + " found”);
return element;
} catch (Exception e) {
Main.logMessage(“AndroidElement " + locator + " not found”);
throw new Exception("Unable to locate element: " + e);
}

Note: Log off button is in the end of the screen and it does scrolls down and log off button is visible in the UI (after it scrolls) but it just waits and then throws ESSocket Time out error.
Also though I pass in 5 seconds wait time webdriver wait it actually wait for longer time around 4 to 5 minutes and then throws socket time out error. I am not sure whether the issue is with the uiautomator2 or issue with wait time?

Please note, same code is working fine on older android versions (< 7.0) with uiautomator1. Also the wait condition works as expected in the lower versions.

I am blocked with executing tests on higher android versions due to the above issue.

Posted issue in github: https://github.com/appium/appium-uiautomator2-server/issues/60