Scroll To / Swipe Action in iOS 8

@sujata_kalluri i figured out a way to scroll the WEbview using javascript executor.

Anyways for native have u tried scrollTo in java and is it working?
can u provide a sample code snippet if available?

Hi @Mobile_Test_Test,

I used below with a native iOS app:

((IOSDriver)driver).scrollTo(text);

where driver is WebDriver instance.

You can directly use IOSDriver or AndroidDriver as required.

Thanks,
Sujata

1 Like

@sujata_kalluri i tried the same and its not working… Element not found/not implemented is what is get as an error.

Im trying to scroll a tableView basically.

P.S… Im in native view and trying to scroll a native element only

Is that element having name attribute and containing text as the same you have given…?

Please let me know…!!!

Regards,
Bhaskar.

Exactly @bhaskar … It has a name attribute and i have given the same… Still its not working…

Hi @Mobile_Test_Test,

scrollTo might not work on TableView.

Thanks,
Sujata

Okie any workaround for that?

You can use Javascript Executor to scroll to a position on the screen

Thanks,
Sujata

Using native_app context here, and I still get the message “Not yet implemented” when trying to scroll left/right with javascript executor.

In our case, we cannot scroll to text because it is a horizontal row of images buttons with no text. I just need to scroll to last item listed on the far right.

Using latest appium 1.4.1 and java client 2.2.0.

Am I doing something wrong?

Using doc provided via the docs:
Of course with my own different coordinate points, but pretty much directly as per the doc.

JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> swipeObject = new HashMap<String, Double>();
swipeObject.put(“startX”, 0.95);
swipeObject.put(“startY”, 0.5);
swipeObject.put(“endX”, 0.05);
swipeObject.put(“endY”, 0.5);
swipeObject.put(“duration”, 1.8);
js.executeScript(“mobile: swipe”, swipeObject);

Hey @sujata_kalluri

Why scrollTo might not work on UITableView when this is designed for?

In the documentation, I found that
`/**

  • Scroll to the element whose ‘text’ attribute contains the input text.
  • This scrolling happens within the first UIATableView on the UI. Use the method on IOSElement to scroll from a different ScrollView.
  • @param text input text contained in text attribute
    */`

It doesn’t work for me, so if you have a tip to use it, let me know.

Thanks,
Ben

Hi @Benoit,

It would work in Native Context, i.e. when AndroidDriver or IOSDriver is used to call scrollTo method.

Could you let me know what error you are getting?

Thanks,
Sujata

Hi @sujata_kalluri,

Actually I don’t have any error message. It just do nothing about it.
The top of the cell can be seen for like 20%, does Appium interprets that like “no need to scroll, it’s already displayed”?

Thanks,
Ben

Hi @Benoit,

Yes. If the cell has certain property that can be compared before and after click then you can use that and then make a call to scrollTo again.

Thanks,
Sujata

Hey @sujata_kalluri,

I can detect my cell, but now is not displayed, is there any change to scrollTo an element?
I tried something like that :

IOSElement logoutElement = (IOSElement)driver.findElementByAccessibilityId(LOGOUT_KEY);
if (!logoutElement.isDisplayed()) {
     ((IOSDriver)driver).scrollTo(logoutElement.getText());
}

But it doesn’t work at all.

In my case I do not want to give a string because the app can be localised, or text can be updated. I really want have something automatic.

Thanks,
Ben

– EDIT –

The only way I found is to detect a cell that is already displayed and swipe down from it to get access to my cell. It’s working but it’s not a good idea if I change the cell order or anything else.

I did that with swipe(SwipeElementDirection.DOWN, 1000); which take a millisec param (good to know because it’s not in the documentation) and had to contains between 0.5sec and 60sec.

Hope it gonna help someone else.

To work around the scrolling issues on iOS, I’ve resorted to using javascript. I’m sure there are better (and less ugly) ways to do this, but here’s my solution in Ruby:

def scroll(scrollable, element)
  driver.execute_script("if (document.readyState === 'complete'){document.querySelector('#{scrollable}').scrollTop = 0;}")
  px = element.location.y - element.size.height - 100
  driver.execute_script("if (document.readyState === 'complete'){document.querySelector('#{scrollable}').scrollTop = #{px};}")
end

The variable ‘scrollable’ is the scrollable element on the page (likely the background div or something) and ‘element’ is the element you’re trying to scroll to.

The reason it scrolls to the top of the page before scrolling to the correct position is because scrollTop doesn’t scroll by a number of pixels, it scrolls to a pixel position, so ‘scrollTop = 600’ will always scroll down (or up) to the 600 px position. ‘element.location’ on the other hand tells you how far from your current position on the page the element is. Scrolling to the top every time just made everything so much easier.

Hi @Benoit,

Is your issue resolved?

Thanks,
Sujata

Hi @sujata_kalluri,

Not really since then. I’ll keep my solution for now, waiting for something easier to use and maintain.

Thanks,
Ben

Hi all ,
there is a solution that worked for me .

MobileElement element = (MobileElement)testCaseObj.getDriverFactory().getAppiumDriver().findElement(By.
xpath(“YOUR ELEMENTS XPATH”));
JavascriptExecutor js = (JavascriptExecutor) testCaseObj.getDriverFactory().getAppiumDriver();
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put(“direction”, “down”);
scrollObject.put(“element”, (element).getId());
js.executeScript(“mobile: scroll”, scrollObject);

		}

Convert your WebElement to MobileElement and then perform the scroll.(One will have to import MobileElement class)
Appium fails to scroll at TableView and CollectionView . Appium can easily scroll on ScrollView.

Hope the solution might be a help.

Hi guys,

For people trying to scroll into UITableView to click to a given UITableViewCell, there is no need to use scrollTo method.

I’ve just tried to click on a IOSElement, giving the accessibilityLabel of my UITableViewCell, without checking if the cell is displayed or not. It automatically scroll to the element if it’s present and clic on it. My mistake was to make something more complicated that it was.

Thanks for your help,
Ben

Hi,

Thank you for the solution. As I wasted more than a week for this and finally found. There are few modifications to be made