C# Appium ScrollTo functionality


As on today, ScrollTo functionality in Appium (dot net binaries) is not working .Instead we need to use Swipe functionality if you want to scroll in the app.

Let us discuss about swipe functionality in Appium. I used TouchAction to perform swipe.It needs x and y coordinates and the way i got those coordinates is explained in the sample code.

new TouchAction(getDriver()).press(startx, starty).waitAction(duration).moveTo(endx - startx, endy - starty).release().perform();

Sample Code:
TouchAction act = new TouchAction(WebDriver);
Size dimensions = WebDriver.Manage().Window.Size;
double screenHeightStart = (dimensions.Height * 0.5);
double screenHeightEnd = dimensions.Height * 0.2;
act.Press(0, screenHeightStart).Wait(100).MoveTo(0 - 0, screenHeightEnd - screenHeightStart) .Release().Perform();

In the Appium documentation for scrolling ,suggested work around for c# is 
Dictionary<string, string> scrollObject = new Dictionary<string, string>();
scrollObject.Add("direction", "down");
scrollObject.Add("element", );
((IJavaScriptExecutor)driver).ExecuteScript("mobile: scroll", scrollObject));
ref:- https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/touch-actions.md

Comments

  1. Thanks alot for the Sample code, it saved lot of my time.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why we need to test the website on different browsers ?

Information on Code Analysis tool

Master degree (CS) VS Job