Nasty bug in List<WebElement> findElements(By var1);

findElements (on a web element) doesn’t like returning no elements. If you perform it on a element such a listview and no elements should be returned, it’ll run amok and return an unrelated element!

I see this both on scrollviews, listviews, on pages like the android settings, or in the notifications list.

For example, the notifications rows are of the form:
// the main notifications scroller
resource-id=“com.android.systemui:id/notification_stack_scroller” class=“android.view.View”

…//structure for each row
…resource-id=“android:id/notification_main_column” class="android.widget.
…// top line of a notification line
…resource-id=“android:id/line1” class=“android.widget.LinearLayout”
…resource-id=“android:id/title” class=“android.widget.TextView”
…// subsequent lines
…resource-id=“android:id/line3” class=“android.widget.LinearLayout”
…resource-id=“android:id/text” class=“android.widget.TextView”

Get the notifications list:
WebElement notificationsPage =
driver.findElementById(“com.android.systemui:id/notification_stack_scroller”);

Get the rows:
List notificationElems =
notificationsPage.findElements(By.id(“android:id/notification_main_column”));

Get a title:
notificationElems.get(x).findElement(By.id(“android:id/title”)).getText()
Get the subsequent lines below:
notificationElems.get(x).findElements(By.id(“android:id/text”)))

Here’s where it gets crazy: if there are no By.id(“android:id/text”)) elements, appium will go out of bounds and grab one from a completely different row!

My planned workaround is to get the bounds of the row, and ignore any returned elements are aren’t contained within the parent’s bounds.