Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to swipe in mobile browser using selenium

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:

action.press(startX, startY).waitAction(2000).moveTo(endX, endY).release().perform();

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.

The current solution is using myScroll handler from javascript. The only disatvantage I see into it , it might not work in browsers such as Internet Explorer version 6 or 7 , but who cares about that.

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’.

 def swipe_photos(direction = "next")
        listing_id = get_listing_id_from_page
        script = "myScroll['listing-details-photos-#{listing_id}'].#{direction}();"
        page.execute_script(script)
 end

Everytime you call the method it will scroll to the next image.

Of course you can scroll backwards

swipe_photos('prev')

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.

Happy testing!

P.S. If you ddon’t know how to to excecute scrips in java you can reffer to this article.

The post How to swipe in mobile browser using selenium appeared first on Testingrepository - Testing repository - selenium webdriver solution and more.



This post first appeared on Testing Repository - Creating Testing, please read the originial post: here

Share the post

How to swipe in mobile browser using selenium

×

Subscribe to Testing Repository - Creating Testing

Get updates delivered right to your inbox!

Thank you for your subscription

×