title: Using appium how can we read/print complete list in a drop down in native as well as Hybrid application?
body: <p>I want to print or read complete contact list using appium (suppose my .apk is a contact application and it shows complete A to Z contacts and by scrolling i can view all of the contacts).</p>
  
  <p>I am able to count/print  contacts shown in the first screen (i.e the screen which shows some contact say 10 contacts by default and for more i have to scroll).i have come to solution of the above and its working for some time but after that it throws an error, Please help how to rectify this issue
  java.lang.IndexOutOfBoundsException: Index: 9, Size: 9</p>
  
  <p>My code is `</p>
  
  <p>AppiumDriver driver = null;
  ArrayList values = new ArrayList();</p>
  
  <pre><code>    DesiredCapabilities cap = new DesiredCapabilities();
      cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Galaxy S4");
      cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
      cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4.4");
      cap.setCapability(MobileCapabilityType.APP_PACKAGE, "com.brainworks.contacts");
      cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.brainworks.contacts.ui.Main");
  
      driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  
      List&lt;WebElement&gt; allContactsOnfirstScreen = driver.findElements(By.xpath("//*[@resource-id='com.brainworks.contacts:id/txt_name']"));
      driver.context("NATIVE_APP");
      Dimension size = driver.manage().window().getSize();
      int StartY = (int)(size.height * 0.70);
      int EndY = (int)(size.height * 0.55);
      int StartX = size.width/2;
  
      for(int i =0;i&lt;200;i++){
          System.out.println("Contacts are = " + allContactsOnfirstScreen.get(i).getAttribute("text"));
          String Values = allContactsOnfirstScreen.get(i).getAttribute("text");
          values.add(Values);
          System.out.println("Value is = " + values);
          String ext = Values;
          String [] a = ext.split(",");
          String [] b = a[a.length-1].split("//]");
          System.out.println("val = " + b[0]);
          driver.swipe(StartX, StartY, StartX, EndY , 1000);
      }`
  </code></pre>
  
  <p>Second way which i have tried </p>
  
  <pre><code>            AppiumDriver driver = null;
  
      // desired cap as above in the first try
  
      // same as above -but now what i am doing is i am printing the list in for loop
              // then do a swipe form last element to first element then again print the new list 
              // and this cycle keeps on running until i reach the end of the list or the parameter
              // in the if loop.
  
      int XOfFirstElement = allContactsOnfirstScreen.get(0).getLocation().getX();
      int YOfFirstElement =  allContactsOnfirstScreen.get(0).getLocation().getY();
  
      System.out.println("X for XOfFirstElement = " + XOfFirstElement);
      System.out.println("Y for YOfFirstElement = " + YOfFirstElement);
  
      int XOfLastElement = allContactsOnfirstScreen.get(allContactsOnfirstScreen.size()-1).getLocation().getX();
      int YOfLastElement =  allContactsOnfirstScreen.get(allContactsOnfirstScreen.size()-1).getLocation().getY();
  
      System.out.println("X for XOfLastElement = " + XOfLastElement);
      System.out.println("Y for YOfLastElement = " + YOfLastElement);
  
      int XOfSecondLastElement = allContactsOnfirstScreen.get(allContactsOnfirstScreen.size()-2).getLocation().getX();
      int YOfSecondLastElement =  allContactsOnfirstScreen.get(allContactsOnfirstScreen.size()-2).getLocation().getY();
  
      System.out.println("X for XOfSecondLastElement = " + XOfSecondLastElement);
      System.out.println("Y for YOfSecondLastElement = " + YOfSecondLastElement);
  
      while(true){
          for(int i = 0 ;i&lt;allContactsOnfirstScreen.size();i++){
              System.out.println("Value is for " + allContactsOnfirstScreen.get(i).getAttribute("text")); 
          }
          driver.swipe(XOfLastElement, YOfLastElement, XOfFirstElement, YOfFirstElement, 1000);
          Thread.sleep(1000L);
          String LastName = allContactsOnfirstScreen.get(allContactsOnfirstScreen.size()-1).getAttribute("text");
          if(LastName.equals("MyLastContactText"))
              break;
      }
  </code></pre>
  
  <p>Now the problem is 
  1.>Every thing is working as expected but what is happening is sometime it prints the duplicate value  (Contact) (may be due to coordinates for that contact do not changes after a swipe)
  2. i am not able to print the last contact name every time cause my if statement in the while loop takes me out and script stops.</p>
  
  <p>if anyone can help then it will be great if any new way plz also let me know Thanks in advance</p>