Appium finds notification tray elements rather than application's elements

I’ve been trying to write Appium tests in Cucumber/Ruby. When I try something like

find("NEXT").click

it responds with

An element could not be located on the page using the given search parameters

I started up the Ruby console (arc) and ran the page command. It takes a while to respond then returns the following:

android.widget.FrameLayout (1)
id: com.android.systemui:id/notification_panel

android.widget.FrameLayout (2)
id: com.android.systemui:id/notification_container_parent

android.widget.FrameLayout (3)
id: com.android.systemui:id/qs_auto_reinflate_container

android.widget.FrameLayout (4)
id: com.android.systemui:id/quick_settings_container

android.widget.RelativeLayout (0)
id: com.android.systemui:id/header

android.widget.LinearLayout (0)
id: com.android.systemui:id/quick_qs_panel

android.widget.Switch (0)
text: On
desc: Wi-Fi,Wifi signal full.,

android.widget.Button (0)
desc: No SIM card,Open Cellular data settings.

android.widget.Button (1)
desc: Battery 100%.,Charging,Open battery details

android.widget.ImageView (2)
id: android:id/icon

android.widget.Switch (1)
text: On
desc: Do not disturb on, alarms only.

android.widget.ImageView (3)
id: android:id/icon

android.widget.Switch (2)
text: Off
desc: Flashlight

android.widget.ImageView (4)
id: android:id/icon

android.widget.Switch (3)
text: Off
desc: Auto-rotate screen,Set to Portrait

android.widget.ImageView (5)
id: android:id/icon

android.widget.LinearLayout (2)
id: com.android.systemui:id/date_time_alarm_group

android.widget.LinearLayout (3)
id: com.android.systemui:id/date_time_group

android.widget.LinearLayout (4)
id: com.android.systemui:id/clock

android.widget.TextView (0)
text: 2:11
desc: 2:11 PM
id: com.android.systemui:id/time_view

android.widget.TextView (1)
text, desc: PM
id: com.android.systemui:id/am_pm_view

android.widget.TextView (2)
text: Wed, May 3
id: com.android.systemui:id/date

android.widget.FrameLayout (7)
id: com.android.systemui:id/settings_button_container

android.widget.ImageView (6)
id: com.android.systemui:id/tuner_icon

android.widget.ImageButton (0)
desc: Open settings.
id: com.android.systemui:id/settings_button

android.widget.ImageView (7)
desc: Open quick settings.
id: com.android.systemui:id/expand_indicator

android.widget.ScrollView (0)
id: com.android.systemui:id/notification_stack_scroller

android.view.View (0)
id: com.android.systemui:id/backgroundNormal

android.widget.FrameLayout (9)
id: com.android.systemui:id/expanded

android.widget.FrameLayout (10)
id: android:id/status_bar_latest_event_content

android.view.ViewGroup (6)
id: android:id/notification_header

android.widget.ImageView (8)
id: android:id/icon

android.widget.TextView (3)
text: Android System
id: android:id/app_name_text

android.widget.LinearLayout (6)
id: android:id/notification_main_column

android.widget.LinearLayout (7)
id: android:id/line1

android.widget.TextView (4)
text: USB debugging connected
id: android:id/title

android.widget.TextView (5)
text: Tap to disable USB debugging.
id: android:id/text

android.widget.FrameLayout (11)
id: com.android.systemui:id/fake_shadow

android.view.View (1)
id: com.android.systemui:id/backgroundNormal

android.widget.FrameLayout (13)
id: com.android.systemui:id/expanded

android.widget.FrameLayout (14)
id: android:id/status_bar_latest_event_content

android.view.ViewGroup (7)
id: android:id/notification_header

android.widget.ImageView (9)
id: android:id/icon

android.widget.TextView (6)
text: Android System
id: android:id/app_name_text

android.widget.LinearLayout (8)
id: android:id/notification_main_column

android.widget.LinearLayout (9)
id: android:id/line1

android.widget.TextView (7)
text: USB charging this device
id: android:id/title

android.widget.TextView (8)
text: Tap for more options.
id: android:id/text

android.widget.FrameLayout (15)
id: com.android.systemui:id/fake_shadow

android.view.View (2)
id: com.android.systemui:id/scrim_behind

android.view.View (3)
id: com.android.systemui:id/scrim_in_front

android.widget.FrameLayout (16)
id: com.android.systemui:id/status_bar

android.widget.LinearLayout (10)
id: com.android.systemui:id/status_bar_contents

android.widget.FrameLayout (17)
id: com.android.systemui:id/notification_icon_area

Which looks like elements from the notification tray, not from my app. If I press the home button, go back to the app, and run page again, it correctly finds the elements from my app.

I tried to run tests on a different app and this does not happen, so there is something particular about this app causing this behavior.

Any ideas what could be causing it?

A hacky solution to this is to put the app in the background and then bring it back, by pressing the “recents” button multiple times. i.e.:

When (/I background then open the app/) do
	press_keycode(187)
	sleep(1)
	press_keycode(187)
	sleep(1)
	press_keycode(187)
	sleep(1)
	press_keycode(187)
end

I run this at the beginning of the test.

1 Like

I am facing same issue. Anyone knows why this is happening with particular app? I am not facing this for other apps. @David_Albers did you find the root cause? Your app switch code looks good though but I was curious about the root cause so that i can resolve it and don’t have to use app switch.