scrollTo in Android opens DropDowns


i am just writing a test which uses scrollTo to find hidden Elements on the screen. Unfortunately the scrollTo clicks often on an Dropdown (Spinner) and makes it impossible to find the given text. Any ideas how to workaround/fix this?

Best Regards


When you say “Hidden Elements”, did you mean the view which are below the screen area and visible only after scrolling?

Yes elements which are visible but not within the current screen area

I took this approach - which can be optimized further -

Write a simple swipe functionality -

public void swipeToBottom() {
	<<sleep for some pre-defined period>>
	mDriver.swipe(1250, 1250, 1250, 250, 2000);  //coordinates may vary based on screen size

Write a for loop[for pre-defined number of swipes], within which -

  1. Search for the element [based on text or any other criteria including UIAutomator search]
  2. If element found, break from for loop.
  3. If not found, call swipe function [above code] and search again[step 1]
1 Like

i am also using a workaround by sending a dpad down keyevent. Thats at least screen size independent.

Can you post your code snippet which you are using for scrollTo text.

You have to use proper element id which has scroll functionality. Mine is working fine.

Here is my code snippet with listview.

     By locator ="listview_id_which_has_scroll_functionality");
    WebElement element = driver.findElement(locator);
    JavascriptExecutor js = (JavascriptExecutor) driver;
    java.util.HashMap<String, String> scrollObject = new java.util.HashMap<String, String>();
    scrollObject.put("direction", "down");
    scrollObject.put("text", "your_text");
    scrollObject.put("element", ((RemoteWebElement) element).getId());
    js.executeScript("mobile: scrollTo", scrollObject);
	private WebElement scrollDown(By query) {
	for (int i = 0; i < 20; i++) {
		WebElement element = findElement(query);
		if (element != null) {
			return element;

	throw new NoSuchElementException("unable to scroll to element for query: " + query);

You can try my code for scrollTo particular and let me know.

Hi Mani,

Your code works for both android and ios? the following code is mine, it’s similar with yours but it only works well on ios.

def scroll_to(self, locator):
    Scrolls to element
    el = self._element_find(locator, True, True)
    driver = self._current_application()
    driver.execute_script('mobile: scrollTo', {"element":})

Can you tell me which app you are testing where you are facing issues with scrollTo text.So we can find solution. To know more about scrollTo you can check my video
Appium Tutorial-Swipe and Scrollto:

Hi All,

As per the screenshot, how to select the city from the drop down using selenium on android mobile using id.

As per your screen shot, I don’t think you need to use drop down.
Just select
WebElement frameLayout = driver.findElement(“android:id/action_bar_container”));
List textView = frameLayout.findElements(By.className(“android.widget.TextView”));
textView.get(0).click(); --> Bangalore
textView.get(1).click(); --> bhubaneshwar

Like this you can select cities