title: Unable to scroll Android app with Appium using Java Client
body: <p>I am unable to scroll down to the bottom of any page in an Android app using Appium.  Multiple approaches were attempted, including those found on Stack Overflow.  (It seems this challenge is common.)  However, all attempts failed.</p>
  
  <p>Environment:</p>
  
  <ul>
  <li>Appium version: 1.6.2</li>
  <li>Appium client: Java (java-client-6.1.0.jar)</li>
  <li>Android versions: 5.1, 6.0.1, 7.1.1</li>
  <li>Java version: jre1.8.0_171</li>
  <li>Selenium version: selenium-java-3.13.0</li>
  <li>App type: Cordova (hybrid); the app is built with Cordova but when running <code>System.out.println(driver.getContext());</code>, the result is <code>NATIVE_APP</code></li>
  </ul>
  
  <p>Please share any alternatives or refinements that can solve this problem.  Any helpful suggestions are greatly appreciated!</p>
  
  <p>The following summarizes the various approaches that were attempted: </p>
  
  <ol>
  
  <li>Approach: scrollIntoView() (various implementations)</li>
  <code>driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(resourceId(\"send-to-email-app\"));").click();</code>
  
  <ul>
  <li>Source: Udemy course</li>
  <li>Error: Does not scroll and NO error</li>
  </ul>
  
  <br>
  
  <li>Approach: Try catch > scrollIntoView()</li>
      <code>try {
              driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Send\"))");
          }catch(Exception e) {
              System.out.println("We got an error scrolling!");
          }</code>
  <ul>
  <li>Source: https://stackoverflow.com/questions/39658626/how-to-scroll-top-to-botton-using-android-driver</li>
  <li>Error: Partially works: the page scrolls down but not far enough</li>
  </ul>
  
  <br>
  
  <li>Approach: Swipe</li>
      <code>driver.swipe(0, Startpoint,0,scrollEnd,1000);</code>
  <ul>
  <li>Source: https://stackoverflow.com/questions/39130591/swipe-or-scroll-to-bottom-in-appium-android</li>
  <li>Error: Swipe is deprecated</li>
  </ul>
  
  <br>
  
  <li>Approach: touchAction.longPress + moveTo</li>
      <code>...touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();</code>
  <ul>
  <li>Source: https://stackoverflow.com/questions/44282417/how-to-scroll-with-appium-1-7-1-using-touchaction</li>
  <li>Error: "driver cannot be resolved"</li>
  </ul>
  
  <br>
  
  <li>Approach: touchAction.longPress + moveTo</li>
      <code>TouchAction touchAction = new TouchAction(driver);
  touchAction.longPress(10, 10).moveTo(x, y).release().perform();</code>
  <ul>
  <li>Source: https://stackoverflow.com/questions/44282417/how-to-scroll-with-appium-1-7-1-using-touchaction</li>
  <li>Error: "The method longPress(LongPressOptions) in the type TouchAction is not applicable for the arguments (int, int)"</li>
  </ul>
  
  <br>
  
  <li>Approach: touch.longPress + moveTo</li>
      <code>...TouchAction touch = new TouchAction(driver);
  touch.longPress(co_ordinates[0], co_ordinates[1]).moveTo(dinates[0], dinates[1]).release().perform();</code>
  <ul>
  <li>Source: https://stackoverflow.com/questions/50304699/how-to-scroll-to-specific-element-inlatest-version-of-appium-using-java</li>
  <li>Error: "takeaway cannot be resolved"</li>
  </ul>
  
  <br>
  
  <li>Approach: moveTo + using coordinates</li>
      <code>actions.press(startX, startY).waitAction(Duration.ofSeconds(2)).moveTo(endX, endY).release().perform();</code>
  <ul>
  <li>Source: http://www.automationtestinghub.com/appium-scroll-examples/</li>
  <li>Error: The 'press' action is deprecated!</li>
  </ul>
  
  <br>
  
  <li>Approach: Using Press Approach to swipe + moveTo</li>
      <code>TouchAction().press(el0).moveTo(el1).release();</code>
  <ul>
  <li>Source: https://stackoverflow.com/questions/49004686/scroll-text-area-with-terms-and-conditions-on-hybrid-app-with-appium</li>
  <li>Error: "The method press(AndroidElement) is undefined for the type Object"</li>
  </ul>
  
  <br>
  
  <li>Approach: touchAction 'tap' using coordinates</li>
      <code>TouchAction touchAction = new TouchAction(driver);
  touchAction.tap(PointOption.point(x, y)).perform();</code>
  <ul>
  <li>Source: https://discuss.appium.io/t/scrolling-to-element-in-android-app-using-java/17208</li>
  <li>Error: None; it partially works: the page scrolls down but not far enough! </li>
  </ul>
  
  <br>
  
  <li>Approach: UiScrollable > Specify Parent scrollable frame and Child element</li>
      <code>MobileElement doeButton = driver.findElement(MobileBy.AndroidUIAutomator(
  "new UiScrollable(new UiSelector().text(\"Android scrollbar test\")).getChildByText("
  + "new UiSelector().className(\"android.widget.TextView\"), \"Doe\")"));</code>
  <ul>
  <li>Source: https://stackoverflow.com/a/51003840/9214050</li>
  <li>Error: "Could not parse UiSelector argument: problem using reflection to call this method"</li>
  </ul>
  
  <br>
  
  <li>Approach: UiScrollable > Specify Parent scrollable frame and 'scrollIntoView' child element</li>
      <code>MobileElement sendEmailButton = driver.findElement(MobileBy.AndroidUIAutomator(
                  "new UiScrollable(new UiSelector().resourceId(\"content\")).scrollIntoView("
                  + "new UiSelector().resourceId(\"add-task-button\"))"));
                  sendEmailButton.click();</code>
  <ul>
  <li>Source: https://stackoverflow.com/a/51003840/9214050</li>
  <li>Error: Does not scroll and NO error</li>
  </ul>
  
  <br>
  
  <li>Approach: Changed “scrollable” attribute for page elements from “false” to “true” using CSS styles</li>
  <ul>
  <li>Source: http://burnignorance.com/html-tips/making-a-smooth-scroll-view-for-android-ios-in-html/</li>
  <li>Error: none, but app won't scroll to bottom of page.</li>
  </ul>
  
  <br>
  
  <li>Approach: Touch actions: “mobile: swipe”, “mobile: scroll” (http://appium.io/docs/en/writing-running-appium/touch-actions/)</li>
      <code>JavascriptExecutor js = (JavascriptExecutor) driver;
        HashMap params = new HashMap();
        params.put("direction", "up");
        js.executeScript("mobile: swipe", params);</code>
  <ul>
  <li>Source: https://stackoverflow.com/questions/32387357/i-cant-make-swipe-gesture-work-for-me-in-appium-using-java#</li>
  <li>Error: "Unknown mobile command "scroll". Only shell,startLogsBroadcast,stopLogsBroadcast commands are supported."</li>
  </ul>
  
  <br>
  
  <li>Approach: HashMap + scrollObject.put</li>
      <code>JavascriptExecutor js = (JavascriptExecutor) driver;
  HashMap scrollObject = new HashMap();
  scrollObject.put("direction", "down");
  js.executeScript("mobile: scroll", scrollObject);</code>
  <ul>
  <li>Source: http://appium.io/docs/en/writing-running-appium/touch-actions/</li>
  <li>Error: "Unknown mobile command "scroll". Only shell,startLogsBroadcast,stopLogsBroadcast commands are supported."</li>
  </ul>
  
  <br>
  
  <li>Approach: Adjusted context of app from "native" to "webview" (since it's a Cordova app)</li>
      <code>appCapabilities.setCapability("autoWebview", "true");</code>
  <ul>
  <li>Source: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md</li>
  <li>Error: "Exception in thread "main" org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible."</li>
  <li>Error: "org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome '58.0.3029'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details. (WARNING: The server did not provide any stacktrace information)"
  </ul></li>
  
  </ol>