Smooth Drag and Drop in Selenium

218 views
Skip to first unread message

ali.a....@gmail.com

unread,
Mar 24, 2021, 1:44:25 AM3/24/21
to Selenium Users
I need to drag and drop a puzzle slider as a human verification, I already did the image recognition part and got the distance needed to move the slider to. But the slider is moving in discrete pattern not smooth with selenium. Anybody has any solution or suggestion?

David

unread,
Mar 25, 2021, 2:35:48 AM3/25/21
to Selenium Users
What does your code look like for the drag & drop? Using native actions from Selenium or executing javascript code to do/simulate the drag & drop?

Ali Jezzini

unread,
Mar 25, 2021, 4:32:58 AM3/25/21
to seleniu...@googlegroups.com
I am using the below code in C#:

                List<int> Track = getTrack(distance);

                var hold = builder.ClickAndHold(slider);
                foreach(int t in Track)
                {
                    hold.MoveByOffset(t, 0);
                }
                    
                hold.Release().Build().Perform(); 
Where the getTrack function returns an offset pattern which takes into consideration acceleration and deceleration of the slider, but all happens in discrete not smooth way.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/gZvSnnMeAoU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/1bca5cab-9606-4fac-9112-ac35cbccf118n%40googlegroups.com.

David

unread,
Mar 25, 2021, 6:42:25 PM3/25/21
to Selenium Users
I don't really have input on what you could do using the native Selenium APIs. But as a workaround, you could attempt the javascript route and see if that does any better: https://ynot408.wordpress.com/2011/09/22/drag-and-drop-using-selenium-webdriver/. But since your code drags the same object (slider) some distance rather than drag a source object into a destination object area, the javascript code might need to be altered for proper behavior.

Soumya Swain

unread,
Mar 26, 2021, 2:09:19 AM3/26/21
to Selenium Users

David

unread,
Mar 26, 2021, 4:21:32 PM3/26/21
to Selenium Users
Also, worst case, if you aren't specifically testing the dragging of the slider functionality but just need to adjust it to test something else, and the slider component you have access to its source code (internal component used in organization/company), could ask the developers to add a back door API (in javascript, etc.) to fake the slider movement so that you can then move on to test what you are really trying to test. Had to do something like that once for a custom component at my workplace.
Reply all
Reply to author
Forward
0 new messages