I want to scroll through the entire app screen instead of using coordinates for iOS elements with Appium

Hi there,

I need help with using scroll function, at the moment i have to use driver.touchperform function with coordinates to scroll to a particular element in iOS simulator with appium.

The current code i use to scroll to elements is this
driver.touchPerform([
{ action: ‘press’, options: { x: 200, y: 74 }},
{ action: ‘wait’, options: { ms: 100 }},
{ action: ‘moveTo’, options: { x: 32, y: 840 }},
{ action: ‘release’ }
]);

Is there a better way of writing the function so i don’t have to use coordinates and the function it self will look through the screen to find the element similar to scrollIntoView function?

Thanks

You could try https://github.com/appium/appium-xcuitest-driver#mobile-scrolltoelement

Could you please show me an example how to use it ?

yo have some options:

  1. as @mykola-mokhnach said, to use the driver’s scroll action.
  2. create your own searchAndScroll method with TouchAction API: JS touch - scroll but it depends on your client version and it does not recommended at all since it is not W3C compatible and already deprecated in the new versions.
  3. create your own searchAndScroll method with Actions API: JS Actions - scroll which is recommended and W3C compatible. Moreover, if you automate other platforms as well, this option is a cross platform one so you need to implement it only once.

you can implement the searchAndScroll method easily by executing this inside a loop and before each scroll try to locate the element (driver.findElement(…strategy…)) if you get an exception then scroll if not then return the element. (you can limit the loop with time so it won’t be infinite and will fail if it won’t find it).
as well, you should not use fixed coordinates. get from the driver the size of the screen and scroll from screenHight * 0.9 to screenHight * 0.1 then you won’t get interrupted.

a good video too see (examples in JS): Swiping your way through Appium by Wim Selles #AppiumConf2021

should i create a helper folder and put this into it then call the method on the functions that i want to run?

Sorry, I don’t quite understand your intention. Could you please explain in more details?

my intention is to add the code into the test folder and reuse it in different spec files, how do i do that?

Should i create a file and add the code there then go to a spec file and call it?

Could you please advice me whats best

Do you use page object model?

I create a parent screen object that all screens inherit from and add all generic methods there.

Hi wreed, yes i do. Thanks i will take a look at this link you sent.

I’m using javascript with webdriverio framework & mocha.

Not a lot of tutorials out there for Javascript. However, here is a 3 part article on using POM with Selenium. Author gives some tips on adapting the model to webdriverio & such:

yeah problem is there is lack of documentation for js with appium