title: In Espresso, how can I perform an action on all matching views without triggering an AmbiguousViewMatcherException?
body: <p>I'm using Espresso to run automated UI tests on an Android app. I want to perform an action on <em>all</em> views that match specified conditions. Espresso does use an <code>allOf()</code> method to find all views that a matcher matches. However, commands such as <code>onView(withText("some text")).perform(click())</code> would throw an <code>AmbiguousViewMatcherException</code> if there is more than one match.</p>
  
  <p>I do have a method for getting the nth matching view when there are multiple matches.</p>
  
  <pre><code>    private static Matcher&lt;View&gt; getElementFromMatchAtPosition(final Matcher&lt;View&gt; matcher, final int position) {
          return new BaseMatcher&lt;View&gt;() {
              int counter = 0;
  
              @Override
              public boolean matches(final Object item) {
                  if (matcher.matches(item)) {
                      if(counter == position) {
                          counter++;
                          return true;
                      }
                      counter++;
                  }
                  return false;
              }
  
              @Override
              public void describeTo(final Description description) {
                  description.appendText("Element at hierarchy position " + position);
              }
          };
      }
  </code></pre>
  
  <p>Sure, I could use this method to loop through every view. But is there a more elegant solution? </p>
  
  <p>And what if I don't know how many matching views there are?</p>