Element cannot be found everytime - Android native App

Env:
Appium server 1.3.1
Java/java client 2.0.0
Real device Nexus 5 - 4.4.4
Mac 10.9
For my tests using Android I always use the uiautomatorviewer to inspect the elements and verify the resource-id, to identify the xpath, or ways to find a reliable locator.
The component I’m trying to find is a Button with a proper resource-id, and text.
I tried to use the resource-id, but it fails most of the time
Then I tried to use a list of Elements using ByChained(className(“android.widget.LinearLayout”), className(“android.widget.Button”)), and checking the Text inside, but it keeps failing most of the times that I tried to run.
I also tried to use an xpath(“.//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.Button”), but usually it finds 2 elements, which are not the target one.
As soon as I download dmg of the latest version, I tried to use the inspector from Appium, but I couldn’t find the component.
I started debug my test, and I kept entering the screen and run the findElements command, and sometimes it finds, and most of the times it doesn’t. When it finds the element, it can use any of the previous locator that I mentioned.
Usually I use a waitDriver to find the element, but all the cases it keeps trying to find the element without success until the TimeoutException occurs.

Shouldn’t be able to see the same elements that uiautomatorviewer can see? Any other advice?

I attached the uiautomatorviewer screenshot

3 Likes

Experiencing the same exact problem.
Sometimes NoSuchElementException and Appium inspector doesn’t display the element. Although, the element is present on device screen and in uiautomatorviewer.

Would love to understand if there’s a fix, a workaround or if I’m doing anything wrong.

Appium server 1.3.1
Real device + emulated Nexus 4 - 4.4.2
Mac 10.10

1 Like

Hi @ranbena,
Probably there is a limit of how many items available can be locate. After this post i found these links:
github/appium
google groups/android
What you can do is try to reduce the number o available items, it did work for me.

Massanori, thanks for the reply.

We’ve looked into this very thoroughly and realized that UiAutomator is to blame for the false negatives. A workaround we found is to restart the UiAutomator process and search for the element once again. 100% success rate.

Unfortunately, this can’t be done with Appium because stopping the process - stops the test run :frowning:
So, we gave up on Appium and instead utilize UiAutomator Python wrapper and restart it’s server when needed.

It’s great to see all test results green again :smile: