0

I have below code :

MobileElement mb = (MobileElement)configuration.driver.findElement(By.className("android.widget.ScrollView"));
JavascriptExecutor js = (JavascriptExecutor)configuration.driver;
HashMap<String, String> scrollObject = new HashMap<>();
scrollObject.put("direction", "down");
scrollObject.put("element", ((MobileElement) mb).getId());
scrollObject.put("text", "Proceed");
        js.executeScript("mobile: scrollTo", scrollObject);

But I'm getting exception

Method has not yet been implemented (WARNING: The server did not provide any stacktrace information)

I am using Java-client-5.0.0.

4 Answers 4

0

Try this

WebElement fromElement=driver.findElement(By.id("locator"));
WebElement toElement= driver.findElement(By.id("locator"));
TouchAction tAction=new TouchAction(driver);
tAction.press(fromElement).moveTo(toElement).release().perform();
4
  • hi prasd thanx for the reply...but it is not working ...
    – Paddy02
    Commented Sep 27, 2017 at 9:46
  • ohh...but this got worked for me....
    – PRasd
    Commented Sep 27, 2017 at 9:59
  • what did you put in locator ??????
    – Paddy02
    Commented Sep 27, 2017 at 10:06
  • can you tell me which libraries are you using ...?
    – Paddy02
    Commented Sep 28, 2017 at 6:03
0

Driver.scrollTo (value) only working when android.widget.ListView have single text in it and it fails when multiple text is present in each row of listView. In my case I have single entry/text in each line. So to resolve your issue you can use below method which I implemented for me and it is working fine.

**public WebElement scroll(String keyword) { HashMap scrollObject = new HashMap(); RemoteWebElement element = (RemoteWebElement)
    driver.findElementByAndroidUIAutomator( "new
    UiSelector().className(\"android.widget.ListView\")");
    JavascriptExecutor js = (JavascriptExecutor) driver; String
    webElementId = ((RemoteWebElement) element).getId();
    System.out.println(webElementId);System.out.println(element);
    scrollObject.put("text", keyword); scrollObject.put("element",
    webElementId); js.executeScript("mobile: scrollTo", scrollObject);
    return element; }**
3
  • hi jensi....this solution not worked for me...its giving exception "Method has not yet been implemented (WARNING: The server did not provide any stacktrace information)".
    – Paddy02
    Commented Sep 27, 2017 at 9:46
  • Ohh..,still not solved. Wait will share you another way. Commented Sep 27, 2017 at 9:58
  • okay jensi.....
    – Paddy02
    Commented Sep 27, 2017 at 10:08
0

Ignore the first answer if it's not useful and use this one if it's useful for you.

WebElement list = driver.findElement(By.id("id of your list"));

         HashMap<String, String> scrollObject = new HashMap<String, String>();
         scrollObject.put("text", "name to search");
         scrollObject.put("element",( (RemoteWebElement) list).getId());
         driver.executeScript("mobile: scrollTo", scrollObject);
         if(scrollObject.containsValue("string to search"))
         {
            System.out.println("Found");
            List<WebElement> list_user = list.findElements(By.id("id of the text view"));
            for (WebElement component : list_user) {
               System.out.println(component.getText());
               if (component.getText().contains("string to search")) {
                    component.click();
                    break;
                } else {
                    System.out.println("Not equal");
                }
         }
         }
         else
         {
             System.out.println("Not Found");
         }
2
  • hi jensi...ur solution is working for listview ...but I have ScrollView...
    – Paddy02
    Commented Sep 27, 2017 at 12:09
  • can you tell me which libraries are you using ...?
    – Paddy02
    Commented Sep 28, 2017 at 6:04
0

After spending many hours I got the working answer. In my case I have scrollview and I want to scroll screen to last button (Proceed).

String str = "Proceed";
            configuration.driver
                    .findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+ str + "\").instance(0))");

str is text which is written on the button.

2
  • This solution is working perfect. But I am working with Android date picker, On year listview scrolling is not working properly. Always scrolling up and down. Please help me to solve this? Note: In date picker year list view is inside scrollview, is this root cause? Commented Jun 26, 2019 at 4:43
  • It's for scrolling for a button which has text (Proceed). I want to scroll screen to last element which is a Logo and has no text. How to do it? Commented Mar 28, 2021 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.