Scroll To / Swipe Action in iOS 8

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

It Has the Simple solution buddy…

WebElement parentElem = driver.findElement(MobileBy.xpath("//UIATableView[1]"));
((IOSElement) parentElem).scrollTo(“String”);

Regrds
**[quote=“Mobile_Test_Test, post:6, topic:4220, full:true”]
@bhaskar @sujata_kalluri

Guys could you put some focus on this?
[/quote]

**

with appium 1.8.2, java-client.There is no scrollTo method for iOS driver.So is there any other way to perform scroll with a tableView for a specific cell?Thanks

with appium 1.8.2,java-client.There is no scrollTo method at all for ios element.So is there other way to perform scrollTo? My requirement is scroll to a specific cell on a tableView;