In Selenium Capybara supports dragging one DOM element onto another with Node#drag_to(element). After calculating positional differences, that method delegates to Selenium::WebDriver::Element#drag_and_drop_by(right_by, down_by)
I've implemented Node#drag_by(right_by, down_by) for the capybara selenium driver which delegates to #drag_and_drop_by directly since there are instances where you don't have a specific DOM element to drop something on, for example moving a draggable marker in Google Maps.
Passing test included at runeb/capybara@ce9eaaa0cf
Awesome!
I have an immediate need for this.
Interestingly I've actually been needing this as well. Hacked around it by going through the Selenium node.
I'm a little concerned that other drivers would have great difficulty implementing this feature, since it needs very complete CSS support to work properly. A headless driver is never going to work with this. It could well be optional, but then it would somehow have to be separated in the spec, so that driver authors could choose not to include this method in their drivers,
I see the problem. But you raise NotSupportedByDriverError on some methods?
I think there should be an opt in possibility of doing these things, with the understanding that not every driver is capable of doing it. All three of us actually needs this method.
What about layering the spec and raising an exception informing you need to move to a higher level (full browser) for certain methods? If you were using Cucumber, that would simply involve re-tagging your scenario with @selenium (or @browser etc).
It's not about the implementation, it's about the _specs_. Authors of other drivers need to be able to opt out of having this feature, because it won't be possible to support it in many of them.
I definitely would need this feature. I don't see how adding this is any different from javascript heavy features. Developers already have to use @javascript tag in their cucumber tests when a headless browser is not enough. I don't see why it is a problem that some drivers raise a NotSupportedByDriverError when they cannot implement the feature.
It's about the SPECS, not the implementation. Driver authors need to be able to opt out of it. It has nothing to do with you as a user.
ok ok sure the speficitations need to be universally agreed upon but there's always going to be features that headless browsers cannot support and selenium and similar drivers that utilize the browser are able to offer. And as testers, it's only natural that we want those features for example when creating an application with heavy javascript requirements.
If the specifications need to be minimal then how about following runeb's suggestion on adding layers to the specs? Would it complicate the design too much?
If drag_by will not make it into Capybara, is there a way to interact directly with selenium webdriver to do this?
@jnicklas, can we see how you hacked around it accessing the Selenium node?
Here's my attempt at the hack, but it's not working...
https://gist.github.com/1093989
Two years and no updates on this issue. Closing it doen.
Wait... closed without an implementation? This would be really useful! Particularly with the new HTML 5 range input type. Should I put in a new request for this? Or can we re-open this?
In case anybody else is looking, here's a monkey-patch you can use to get a drag_by function for now: https://stackoverflow.com/questions/10866960/how-do-i-drag-a-jquery-slider-handle-from-within-capybara-and-chromedriver
@mitsy It was closed because no one ever submitted a PR that matched the requirements discussed above. If you want to submit a PR that does meet the requirements it will be considered.
Most helpful comment
Wait... closed without an implementation? This would be really useful! Particularly with the new HTML 5 range input type. Should I put in a new request for this? Or can we re-open this?
In case anybody else is looking, here's a monkey-patch you can use to get a drag_by function for now: https://stackoverflow.com/questions/10866960/how-do-i-drag-a-jquery-slider-handle-from-within-capybara-and-chromedriver