title: Espresso - get text of element
body: <p>If I have an "AppCompatTextView" element that I can access by:</p>
  
  <pre><code>onView(withId(R.id.allergies_text))
  </code></pre>
  
  <p>From Layout Inspector:</p>
  
  <p><a href="https://i.stack.imgur.com/Bl23m.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Bl23m.png" alt="enter image description here"></a></p>
  
  <p>Is there a way I can access the text of the element in Android Studio? (to access whatever text is there... not check if some text exists in the element)</p>
  
  <p>I tried to do:</p>
  
  <pre><code>val tv = onView(withId(R.id.medical_summary_text_view)) as TextView
  val text = text.text.toString()
  print(text)
  </code></pre>
  
  <p>But I get the error:</p>
  
  <p><em>android.support.test.espresso.ViewInteraction cannot be cast to android.widget.TextView</em></p>