I am making a test using Espresso, first I open the action bar:
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
Everything ok up to here, but then I want to click on an option menu:
onView(withId(R.id.action_menu)).perform(click());
The menu layout xml has an option with id: "action_menu".
I get an error:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: ***.********.******.android.debug:id/action_menu
If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:android.support.v7.widget.ListPopupWindow$DropDownListView{43fd3f58 VFED.VC. .F...... 24,24-612,168}
I got this step to work by using:
onView(withText(R.string.action_report)).perform(click());
I would like to know what is going wrong with the id though.
Any ideas?
It seems that the view representing the menu does not know the id, but only the text of an item. I am new to Espresso and therefore cannot give more details, but this post is related to your problem : Espresso NoMatchingViewException when using withId matcher
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With