Cannot locate elements using content-desc

Dear guys,

Now i am testing an App on Android. However when i use uiautomator to check the available elements, there’re only context-desc available. No resource-id, no Index and also no some other identifier.

Then i try to use findElementByAccessibilityId to identify the element i want to click. But i doesn’t work.

I was wondering if anyone met this before ? Please help

Below are the screenshot when i use uiautomator .


Thanks in advance

Some uiautomator feature such as resource id (API 18+) depend on the API level of Android.
http://developer.android.com/tools/help/uiautomator/UiSelector.html#resourceId(java.lang.String)

Thanks,bootstraponline

I’m using API 19 and the OS is Android 4.4.2

From the uiautomatorviewer screenshot it looks like you’re inspecting a WebView. Elements contained within a webview wouldn’t normally contain native element specific identifiers such as a resource id.

So according to this, do we have any solutions that i can identify the button ‘CONTINUE’?

Try switching to the webview context.

Many thanks. i will try to switch Webview. Once i got a solution, i will post on

@bootstraponline
Hello, i have tried to switch to WEBVIEW(pls refer below screenshot), however i still got some errors.

For the error message, please refer below.
Now i am totally have no idea…

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3.92 seconds
Build info: version: ‘2.43.1’, revision: ‘5163bceef1bc36d43f3dc0b83c88998168a363a0’, time: ‘2014-09-10 09:43:55’
System info: host: ‘ADMINIB-757P3E7’, ip: ‘9.115.129.62’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.7.0_67’
Session ID: 966a6866-2252-424c-a950-34b4e0d36a8d
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{platform=WINDOWS, app=C:\Users\IBM_ADMIN\EclipseLuna\bankingapptest\apps\StarterAppsStarterAppBankAndroid.apk, javascriptEnabled=true, appActivity=.StarterAppBank, browserName=Android, networkConnectionEnabled=true, desired={platformVersion=4.4, app=C:\Users\IBM_ADMIN\EclipseLuna\bankingapptest\apps\StarterAppsStarterAppBankAndroid.apk, platform=WINDOWS, deviceName=Android Emulator, platformName=Android, appActivity=.StarterAppBank, appPackage=com.StarterAppBank}, locationContextEnabled=false, appPackage=com.StarterAppBank, platformVersion=4.4, databaseEnabled=false, platformName=Android, deviceName=Android Emulator, webStorageEnabled=false, warnings={}, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:176)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at io.appium.java_client.android.AndroidDriver.findElementByAndroidUIAutomator(AndroidDriver.java:264)
at bankingapp.bankingapptest.BankingAppTest.AppTest(BankingAppTest.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:77)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:56)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

I’m not sure. That error message isn’t too informative.

Hey suroit,
Probably You can use xpaths.
The Appium Inspector for iOS version gives the xpaths.(Appium v1.2.2) dmg
It works in my case.

Thanks, Shirodkar. I will try to use XPATH.

Hi Suroit,

Were you able to locate elements using xpath on WEBVIEW? I keep getting the error message:

derived selector: (:by => xpath) //android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.ImageView[1]
info: --> POST /wd/hub/session/7012df53-fe0c-4670-966e-1fe6a804c470/element {“using”:“xpath”,“value”:"//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.ImageView[1]"}
info: [debug] Proxying command to 127.0.0.1:9515
info: [debug] Making http request with opts: {“url”:“http://127.0.0.1:9515/wd/hub/session/d806f724c5e912760b6f6f6362a8df94/element",“method”:“POST”,“json”:{“using”:“xpath”,“value”:"//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.ImageView[1]”}}
info: [debug] Responding to client with error: {“status”:7,“value”:{“message”:“An element could not be located on the page using the given search parameters.”,“origValue”:“no such element\n (Session info: webview=)\n (Driver info: chromedriver=2.10.267517,platform=Mac OS X 10.9.5 x86_64)”},“sessionId”:“7012df53-fe0c-4670-966e-1fe6a804c470”}
info: <-- POST /wd/hub/session/7012df53-fe0c-4670-966e-1fe6a804c470/element 500 2370.214 ms - 297
info: --> GET /wd/hub/session/7012df53-fe0c-4670-966e-1fe6a804c470/screenshot {}
info: [debug] Proxying command to 127.0.0.1:9515
info: [debug] Making http request with opts: {“url”:“http://127.0.0.1:9515/wd/hub/session/d806f724c5e912760b6f6f6362a8df94/screenshot",“method”:"GET”}
info: [debug] Proxied response received with status 200: “{“sessionId”:“d806f724c5e912760b6f6f6362a8df94”,“status”:13,“value”:{“message”:“unknown error: unhandled inspector error: {\“code\”:-32603,\“message\”:\“Unable to capture screenshot\”}\n (Session info: webview=)\n (Driver info: chromedriver=2.10.267517,platform=Mac OS X 10.9.5 x86_64)”}}”
info: <-- GET /wd/hub/session/7012df53-fe0c-4670-966e-1fe6a804c470/screenshot 200 148.491 ms - 290
Can’t take screen shot so skiping it
unknown error: unhandled inspector error: {“code”:-32603,“message”:“Unable to capture screenshot”}
(Session info: webview=)
(Driver info: chromedriver=2.10.267517,platform=Mac OS X 10.9.5 x86_64)

Hi Shankybnl,

Before you locate elements on WEBVIEW, you need to switch to WEBVIEW in the code.

Set contextNames = driver.getContextHandles();

    for (String contextName : contextNames) {

      System.out.println(contextName);

      if (contextName.contains("WEBVIEW")){

        driver.context(contextName);

      }else

      {

          System.out.println("no WEBVIEW"); 

      }

    }
1 Like

Thank you Suroit.

I was able to switch to WEBVIEW context but unable to locate elements in the WEBVIEW. Actually i was using xpath (//android.widget.TextView…) which works in NATIVE_APP. On using web xpath (//input[@name=‘element’]), issue has been resolved.

That’s weird. Actually i haven’t solve this problem so far. In my App, i not be able switch to WEBVIEW context. In general, when we switch to WEBVIEW, we can locate elements by XPATH or some other methods.
But, yes, like you said, it doesn’t work.

Sorry that i cannot help on this for now. i will keep searching on this case, once i got the solution, i will let you know.

Hi Guys,

I am new to Appium and as per the screenshot I am trying to find resource-id of whatsapp but it is not getting displayed in uiautomatorviewer. I have samsung Duos with Android version 4.4.2. So can you please help to find resource-id using uiautomator viewer