How to swipe in mobile browser using selenium
Nowdays mobile it’s a must , all websites are responsive and web features are always build in to provide native experience. Since you are here , I guess you wander how to swipe in mobile browser using selenium? How to use selenium swipe actions?
Well , you might already tried the solution from stackoverflow using getLocation() and action class:
Forget about it , at least I did forget about it as is not as reliable as I would like it to be. I did tried to find a solution allover the internet to basically be able to tell the browser to swipe that image/locator back and forward.
Last week one of my coleagues needed the same thing and she basically had a chat with one of our developers , and here you are reading the solution that the dev provided to us.
Swipe in mobile web
Since my current project is ruby-capybara based I will give you the solution in ruby but you’ll get how to do it in your current programing language.
Given a property page : https://m.zoopla.co.uk/to-rent/details/46631845
In my case the image class that I have to swipe is ‘listing-details-photos-46631845’.
Everytime you call the method it will scroll to the next image.
Of course you can scroll backwards
You can check more technical details about the scroll handler here.
If you are wandering when to stop scrolling forward and backwards , well its simple you can get the total number of object that you have to scroll and wrap this method up in a for loop 🙂 .
When can you use this solution?
You can use it on desktop , you can use it on mobile web testing using user agents , and you can use it if you are running your mobile web tests using appium.
You CAN’T apply this solutiuon on native apps.
This is pretty much the same like scroll to element only is using a different handler.
P.S. If you ddon’t know how to to excecute scrips in java you can reffer to this article.