1
votes

I wish to use the capybara method drag_to in order to manually sort items on a page. Below is my code:

pos2 = find('#first_element')
target = find(#second_element)
pos2.drag_to(target)

However I get the error message:

undefined method `drag_to' for nil:NilClass (NoMethodError)

Am I invoking the method incorrectly? I am attempting to implement as defined here: http://rubydoc.info/gems/capybara/0.4.0/Capybara/Element#drag_to-instance_method

Please note I am able to use other capybara methods fill_in, visit etc without any problems...

Any help would be greatly appreciated!

1
The exception says that pos2 is nil. That suggests you are not finding the first element correctly. It might help to show your actual code.Justin Ko
Could you please add your actual code? It's obvious that provided snippet wouldn't work since there is typo. There should be find('#second_element') instead of find(#second_element)lifus
@Justin - Thanks, you were right, I was not finding the first element. I changed it so that it now uses xpath so my code is: pos2 = find(:xpath, '//*[@id="people_container"]/div[1]/img') target = find(:xpath, '//*[@id="people_container"]/div[3]/img') pos2.drag_to(target) This does not cause an error but the elements are not moved. :-(user1523236

1 Answers

0
votes

#drag_to actually won't move sortable elements, since you're not moving it "to" anywhere as much as a set distance in a certain direction. Selenium implements #drag_by but it is not yet supported by Capybara.

See also:

https://github.com/jnicklas/capybara/issues/222

https://github.com/jnicklas/capybara/issues/119