# Please help me to write appium code for for loop in android app

**URL:** <https://discuss.appium.io/t/please-help-me-to-write-appium-code-for-for-loop-in-android-app/7739>\
**Category:** Issues/Bugs\
**Created:** [January 4, 2016, 3:01am UTC](https://discuss.appium.io/t/please-help-me-to-write-appium-code-for-for-loop-in-android-app/7739 "2016-01-04T03:01:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajai2608](https://discuss.appium.io/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@ajai2608](https://discuss.appium.io/u/ajai2608)\
**Post date:** [January 4, 2016, 3:01am UTC](https://discuss.appium.io/t/please-help-me-to-write-appium-code-for-for-loop-in-android-app/7739/1 "2016-01-04T03:01:13Z")

</div>

I have 3 screens where 1st screen has N number of buttons in list view format similarly in 2nd screen and third screen has next button which I need to press N times and from third I need to back on first screen then second screen then third screen.

---

<div class="post-metadata">

**Author:** ![pr4bh4sh](https://discuss.appium.io/user_avatar/discuss.appium.io/pr4bh4sh/32/1724_2.png) [@pr4bh4sh](https://discuss.appium.io/u/pr4bh4sh)\
**Post date:** [January 4, 2016, 6:01am UTC](https://discuss.appium.io/t/please-help-me-to-write-appium-code-for-for-loop-in-android-app/7739/2 "2016-01-04T06:01:25Z")

</div>

Screenshot would help to understand you scenario. Please attach if you can.

---

<div class="post-metadata">

**Author:** ![ajai2608](https://discuss.appium.io/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@ajai2608](https://discuss.appium.io/u/ajai2608)\
**Post date:** [January 4, 2016, 7:33am UTC](https://discuss.appium.io/t/please-help-me-to-write-appium-code-for-for-loop-in-android-app/7739/3 "2016-01-04T07:33:12Z")

</div>

Screen shots

 ![](https://discuss.appium.io/uploads/default/original/2X/b/b4f15a39f85638fe154c17b245abd4a001724808.png) ![](https://discuss.appium.io/uploads/default/original/2X/2/2220683401ece04561cdf04ec4211bbf0c3bb047.png) ![](https://discuss.appium.io/uploads/default/original/2X/7/7c5f0015b407b824f345fb462bfe29ab70c3c6db.png) ![](https://discuss.appium.io/uploads/default/original/2X/b/b044b34ddc621481e84f76735e37ebc0b3f67eec.png)

---

<div class="post-metadata">

**Author:** ![amitjaincoer191](https://discuss.appium.io/user_avatar/discuss.appium.io/amitjaincoer191/32/5339_2.png) [@amitjaincoer191](https://discuss.appium.io/u/amitjaincoer191)\
**Post date:** [January 5, 2016, 7:58am UTC](https://discuss.appium.io/t/please-help-me-to-write-appium-code-for-for-loop-in-android-app/7739/4 "2016-01-05T07:58:29Z")

</div>

this looks dynamic like  
class vi has 2 subjects  
class vii has 2+ subjects

then  
each subject have dynamic number of multiple sections with questions

```
List<WebElements> screen1 = driver.findElements(By.className("buttons in list view"));
for (int i=0;i less then screen1.size();i++){
   screen1.get(i).click(); // this takes us to screen 2 for first class like class vi
   List<WebElements> screen2 = driver.findElements(By.className("get all subject of class v1"));  
      for (int j=0;j less then screen2.size();j++){
             screen2.get(j).click();
                List<WebElements> screen3 = driver.findElements(By.className("get all question of class v1 subject 1"));  
                        for (int k=0;k less then screen2.size();k++){
                                        screen3.get(k).click(); 
                                       // now we reached to questions u can perform verification here                                        
                       } // end of screen 3 for loop

          } // end of screen 2 for loop
}// end of screen 1 for loop

```

Challenge here is we need a single locator that build list of all WebElements on a page we need to click.

---

<div class="post-metadata">

**Author:** ![ajai2608](https://discuss.appium.io/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@ajai2608](https://discuss.appium.io/u/ajai2608)\
**Post date:** [January 5, 2016, 1:23pm UTC](https://discuss.appium.io/t/please-help-me-to-write-appium-code-for-for-loop-in-android-app/7739/5 "2016-01-05T13:23:16Z")

</div>

@amitjaincoer191,  
Its working as expected but there is one problem, It is picking random list item from every screen while it should be sequence.  
Please help me out to pick the item from list one by one not randomly.
