Java client should have a scrollTo(xpath) similar to scrollTo(text) method

If text for an element is not available than scrollTo(xpath) method might be useful.
Just a suggestion.

1 Like

Yes I agree there should be some method where we can use xpath and scroll in java client itself. But You can edit and use below code for xpath as a workaround.

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();
scrollObject.put(“text”, keyword);
scrollObject.put(“element”, webElementId);
js.executeScript(“mobile: scrollTo”, scrollObject);
return element;

Yup Thanks for the workaround. Will use it. Hope java client comes up with a method soon.
I am using this for now…works fine.
((JavascriptExecutor) driver).executeScript(“arguments[0].scrollIntoView(true);” , element);

1 Like

Very Nice Idea… @Mayuresh_Shirodkar. because ScrollTo(text) is taking so much of time and also it doesn’t support for move to a particular element… :smile:

1 Like

Also the scrollTo method should be such that it can be used for Webview as well as Native view.