Verify items in a popup menu with espresso
<p>I have a popup menu. User interface screenshot provided below. I want to verify some items in the menu by clicking them and verify what's happening.</p>
<p>No matter what I do, I am unable to select items in the popup menu. The menu does not have an ID and I don't think it's possible to set the ID of a menu.</p>
<p>I've tried different things like:</p>
<pre class="lang-java prettyprint-override"><code>onView(nthChildOf(anyOf(withId(android.R.id.title)), 1)).perform(click());

onView(withText(&quot;5 sekunder&quot;)).perform(click());
</code></pre>
<p>But nothing works. How do I click on an item in a popup menu?</p>
<h4>EDIT</h4>
<p>To be clearer: This happens when I click on the dots on the right side of the action bar to expand the sub-menu. The sub-menu in my case always consists of three items. The closest I've come to a solution is:</p>
<pre><code>onData(anything()).atPosition(2).perform(click());
</code></pre>
<p>But most of the time it opens the first item and not the item in position two. This results in:</p>
<pre><code>No activities in stage RESUMED. Did you forget to launch the activity. (test.getActivity() or similar)?
</code></pre>
<p><a href="https://i.stack.imgur.com/WXZ3A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WXZ3A.png" alt="Screenshot" /></a></p>