Unable to find out element in native android app from search results


#1

There are no elements in the current page, I see the only className but remaining sections also having the same className, I have tried it so many ways but still getting null pointer exception

  1. Taken from Parent node but this case also not working.
  2. Used findElements:

List elements = driver.findElements(By.className(“android.widget.RelativeLayout”));
element.get(0).click();

  1. driver.findElementByXPath("//android.widget.TextView[@index=‘0’]).click();

Thanks


#2

All elements are visible in your screen. Even the texts (Y C., PREMIUM, Irvine, CA) are visible.

You want to tap on first element of the list? Look for the parent element of the results list and then look for the class names below that parent element, for instance.


#3

Hi Telmo_Cardoso,

Yes, there are visible texts but not every time, it will change randomly (Eg: take facebook news feed )

Yes I have tried it to take parent element and the child element to click, still getting null pointer exception.

See Parent list className is diff when compared to the child (See the first screenshot) element className

so unable to click first member


#4

To tap on first element:

driver.findElement(By.id(“com.care.android.careview.debug:id/recyclerview”)).findElements(By.className(“android.widget.RelativeLayout”)).get(0).click();

Off course this shouldn’t be so directly. You should use waits and verification if elements is retrieving any element before getting the first index to avoid NullPointer, etc.


#5

@Telmo_Cardoso this will only work for first element. With second one will not cause there are many RelativeLayouts inside each other.

@kumar.abdasu best solution ask DEV to add resource-ID to RelativeLayouts on first screenshot. It is 1 line of code.


#6

yes @Aleksei I’m giving the solution he wanted :smiley:

Using xpath he can get the direct childs with that class only:

"//" + CLASSNAME_ANDROID_RECYCLER_VIEW + "/" + CLASSNAME_ANDROID_RELATIVELAYOUT

#7

@Telmo_Cardoso yes. this is better :slight_smile: and may be used as final when DEV can’t set IDs.