Xamarin Uitest: How to click on the particular element of ListView

I have a List View in which on each list there is 3 field namely label ,button and image.
I want to to click on the button of particular named label.
How can I achieve it?

Best Answer

Answers

  • SreeeeSreeee INMember ✭✭✭✭✭
    edited October 2018

    You need to use MVVM for this.
    Here is a sample blog.

  • ana_riana_ri Member ✭✭

    @Sreeee said:
    You need to use MVVM for this.
    Here is a sample blog.

    I have used MVVM.
    I need to know that how can I click on particular element while doing xamarin.uitest?

  • JohnHardmanJohnHardman GBUniversity mod

    @ana_ri said:
    I have a List View in which on each list there is 3 field namely label ,button and image.
    I want to to click on the button of particular named label.
    How can I achieve it?

    Have the developers given unique (and predictable) ids to the Buttons, or to a Layout type that contains the Button, or the the ViewCell containing a Layout that contains the Button? If not, get the developers to add those ids.

    Can it be done without using ids? Yes, it can, but using ids is the preferred method.

  • ana_riana_ri Member ✭✭

    @JohnHardman said:

    @ana_ri said:
    I have a List View in which on each list there is 3 field namely label ,button and image.
    I want to to click on the button of particular named label.
    How can I achieve it?

    Have the developers given unique (and predictable) ids to the Buttons, or to a Layout type that contains the Button, or the the ViewCell containing a Layout that contains the Button? If not, get the developers to add those ids.

    Can it be done without using ids? Yes, it can, but using ids is the preferred method.

    They have given a Automation Id

  • JohnHardmanJohnHardman GBUniversity mod

    @JohnHardman said:
    Have the developers given unique (and predictable) ids to the Buttons, or to a Layout type that contains the Button, or the the ViewCell containing a Layout that contains the Button?

    @ana_ri said:
    They have given a Automation Id

    Which of the three options listed is the case?

    Given that there are likely to be multiple Items in the ListView, are the AutomationIds unique and predictable, or does each Item use the same AutomationIds?

  • ana_riana_ri Member ✭✭

    @JohnHardman said:

    @JohnHardman said:
    Have the developers given unique (and predictable) ids to the Buttons, or to a Layout type that contains the Button, or the the ViewCell containing a Layout that contains the Button?

    @ana_ri said:
    They have given a Automation Id

    Which of the three options listed is the case?

    Given that there are likely to be multiple Items in the ListView, are the AutomationIds unique and predictable, or does each Item use the same AutomationIds?

    Each item use the same automation id

  • JohnHardmanJohnHardman GBUniversity mod

    @ana_ri said:
    Each item use the same automation id

    So, for the test that you want to implement, I assume that you need to find the item that has particular Text in the Label, and then press the Button for that same item?

    Are the Label and Button children of the same Layout?

    If so, your test will need to find the Label with the desired Text, then get that Label's parent, then get the Button that is a child of that same parent. It should just be those three steps as long as the desired item is visible. If the ListView content needs to be scrolled in order to display the desired item, it will be more work.

  • ana_riana_ri Member ✭✭

    @JohnHardman said:

    @ana_ri said:
    Each item use the same automation id

    So, for the test that you want to implement, I assume that you need to find the item that has particular Text in the Label, and then press the Button for that same item?

    Are the Label and Button children of the same Layout?

    If so, your test will need to find the Label with the desired Text, then get that Label's parent, then get the Button that is a child of that same parent. It should just be those three steps as long as the desired item is visible. If the ListView content needs to be scrolled in order to display the desired item, it will be more work.

    How can we do it?

  • JohnHardmanJohnHardman GBUniversity mod
    edited October 2018

    @ana_ri said:
    How can we do it?

    There are three clearly defined steps. Address them one at a time, checking the results with Repl.

    Take a look at using Query with Marked

    Query(c => c.Marked(text))
    

    And for parent, child and sibling relationships see https://developer.xamarin.com/api/type/Xamarin.UITest.Queries.AppQuery/

    Note that you may be able to query directly for sibling, rather than do parent and then child, so you might do it all in two steps rather than three.

  • RuthCrawfordRuthCrawford Member ✭✭

    good topic!

  • ana_riana_ri Member ✭✭

    @JohnHardman said:

    @ana_ri said:
    How can we do it?

    There are three clearly defined steps. Address them one at a time, checking the results with Repl.

    Take a look at using Query with Marked

    Query(c => c.Marked(text))
    

    And for parent, child and sibling relationships see https://developer.xamarin.com/api/type/Xamarin.UITest.Queries.AppQuery/

    Note that you may be able to query directly for sibling, rather than do parent and then child, so you might do it all in two steps rather than three.

    I am not getting it..How to run sibling queries

Sign In or Register to comment.