Visible elements are not detected in appium

I have a simple page with a proper resource id. When trying to search for this element, appium script is failing with reason No Such element found.

MobileElement el = (MobileElement) driver.findElement(By.id("com.app:id/tvEmail"));

I tried adding implicit wait for 30seconds, and explicit waits, and Thread.sleep();

Nothing seems to work. Also, there is an inconsistency while searching for this element. Sometimes the element is being searched and most cases it is failing.

Note: the page is loaded properly for all the elements to be visible

  1. can you see your element in pageSource ?
  2. can you see your element in “UI Automator Viewer” (see “tools” folder of android sdk) ?
  1. Yes the element can be seen from pageSource.
    This is the element found ater printing pageSource.

    <android.widget.TextView index="3" package="com.app" class="android.widget.TextView" text="[email protected]" resource-id="com.app:id/tvEmail" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,622][1080,681]" displayed="true" />

try to change id to AccessibilityId

try:

MobileElement el = (MobileElement) driver.findElement(MobileBy.id("tvEmail"));
MobileElement el = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().resourceIdMatches(\".*tvEmail\")"));

@Aleksei

I have tried both the ways but it is not helping me much. Sometimes there is a success in searching the element, while most of the times it is failing