Friday, 11 March 2016

How to Match Child View of a View in Espresso

Hi all clicking on child view of a view is mostly used in case ListView whenever we want to click on the perticular column or part inside the row. We have already seen a ListView Example in the previous post where we had around 50 rows containing text and toggle button. We will just use the same example and learn how to match a child view inside a view in espresso.

App Under Test -
Consider that we have  a app with ListView and the ListView is divided into two columns the first column is text and second column is number of characters in the text.The list view has unique text in first column but second column has repetitive entries.

Test Case Scenario-
1. check one row in list where with Text "Dog" and "3".
2. click on 3 where 3 has occurred multiple times for different rows but we want to click on "3" within the row with text "Dog.

Test Case -
As you all are already familiar with espresso. I am just giving you the below simple test case to achieve our test case goal.

public void testChildView()

I hope this post helps you find your code coverage for your test suit :)
Please Share your feedback in comments section below and follow QA Automated to get latest post update.Happy Testing :-)


  1. Hi, I have a LinearLayout and I am adding editText dynamically to it, I want to write to that edittext but cant as it has same ids can you please help.

  2. Hi,
    You can try with other attributes like text, class name, content -desc etc.


  3. Using the hierarchy, how can I validate the two Text("Protocols" and "Email") on this screen? Could you please Help me.
    (0) LinearLayout
    (0) RelativeLayout
    (1) RelativeLayout
    (0) LinearLayout
    (0) TextView: Protocols
    (0) TextView: Email