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?
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.
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.
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: