In C# Not able to scroll down to particular element or from particular element


#1

Message: System.Argument Exception: The IWebDriver object must implement or wrap a driver that implements IHasTouchScreen.
Parameter name: driver

Here is the code attached
AndroidElement element = driver.FindElementByXPath("//android.widget.TextView[@text=‘development nearby’]");
TouchActions action = new TouchActions(driver);
action.Scroll(element, 10, 1100);
action.Perform();


#2

#3

I am unable to scroll, the code is not prompting error but not performing action even after execution


#4

here is a Java implementation to scroll until a certain text or element is displayed, feel free to adapt it to C#.
make sure you are using latest appium and c# client version in your case.
Method swipes up, but you can modify it as your wish.

public void swipeUpUntilTextExists(String expected, int times) {
	int i = 1;
	while (!driver.getPageSource().contains(expected)) {
		log.info("Text not found, swiping...");
		swipe();
		i++;
		if (i == times)
			break;
	}
	log.info("Text found. Stop swiping");
}

public void swipeUpUntillElementIsDisplayed(MobileElement expectedElement, int time) {
	int i = 1;
	do {
		swipe();
		i++;
		if (i == time)
			break;
	} while (!expectedElement.isDisplayed());

swipe method:

public void swipe(){
Dimension size = driver.manage().window().getSize();
	// calculate coordinates for vertical swipe
	int startVerticalY = (int) (size.height * 0.8);
	int endVerticalY = (int) (size.height * 0.21);
	int startVerticalX = (int) (size.width / 2.1);
new TouchAction<>(driver).press(point(startVerticalX, startVerticalY))
						.waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))
						.moveTo(point(startVerticalX, endVerticalY)).release().perform();}