Search code examples
javaappium

How do you select index of the list particular value?


I have a list element and when user types 1 it clicks on index 0 element, when user types 2 it clicks on index 1 element, when user types 3 it selects index 2 element and when user types 4 it clicks on index 3 element.. How would you write the method in correct way?

AndroidFinBy(id="example") List list;

 public boolean list(int list_view) {

    if(list_view == 1) {
        list.get(0).click();
    }else if(list_view ==2){
        chipList.get(1).click();
    }else if(list_view ==3){
        list.get(2).click();
    }else if(list_view ==4){
         list.get(3).click();
    return true;
    }
    return false;

My code does not work keeps selecting the wrong element?


Solution

  • public boolean list(int list_view) {
        if(list.size() >= list_view && list_view > 0) {
            list.get(list_view - 1).click();
            return true;
        }
        return false;
    }