[Watir-webdriver] - Drag and drop using watir webdriver

998 views
Skip to first unread message

watir webdriver

unread,
Jul 3, 2013, 9:53:28 AM7/3/13
to watir-...@googlegroups.com
Hi there,

I'm trying to drag and drop an element in webpage through the below code:

Step def:
When(/^I drag and drop Basket rule to the position slot$/) do
@browser.span(:class => "draggable ui-draggable").drag_and_drop_on(@browser.div(:class => "droparea ui-droppable ui-sortable"))
end

The scenario is passing but on the webpage its just high lighting the draggable element.(drop is not working)

HTML code for draggable code:
<tr>
<td>
<span class="draggable ui-draggable" full="Basket" aid="BASKET"> Basket</span>
</td>
<tr>


HTML code for droppable code:
<div id="0" class="droparea ui-droppable ui-sortable">

Anyone can help me with this issue ?

Thanks in-advance.


Joe Fleck

unread,
Jul 3, 2013, 1:08:24 PM7/3/13
to Watir General
Hi,

I have notice different behavior in the drag n drop method depending on the os and browsers used.  I originally developed the drag_n_drop step on a Mac/Firefox combo and will see the object being moved.  Though when I run the same script on a WIN7 IE8 VM the visible object doesn't move but the steps following that complete with success.  

Joe




--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
 
---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

John Fitisoff

unread,
Jul 3, 2013, 10:12:01 AM7/3/13
to watir-...@googlegroups.com
I ran into a similar thing recently, haven't had time to circle back and see why, may have been user error. It wasn't working in using the native watir method but I did get things to work by using the webdriver ActionBuilder. At that point I dropped it (so to speak) because drag and drop wasn't necessary for what I was doing. And I didn't dig into the Ruby code to see what, if any difference there was. But it may be worth trying it this way (you can break it down further if you need to but action.drag_and_drop was enough for me).

http://selenium.googlecode.com/svn@7079/trunk/docs/api/rb/Selenium/WebDriver/ActionBuilder.html

el1 = driver.find_element(:id, "some_id1")
el2 = driver.find_element(:id, "some_id2")
driver.action.drag_and_drop(el1, el2).perform




From: watir webdriver <watirweb...@gmail.com>
To: watir-...@googlegroups.com
Sent: Wednesday, July 3, 2013 6:53 AM
Subject: [wtr-general] [Watir-webdriver] - Drag and drop using watir webdriver

watir webdriver

unread,
Jul 8, 2013, 9:53:31 AM7/8/13
to watir-...@googlegroups.com
Hi,
I've tried but its throwing below error :

      undefined method `action' for #<Watir::Browser:0x3010cf8> (NoMethodError)

I'm using native events and not sure how to use watirwebdriver ActionBuilder.Can anyone help me with this issue ?

Implemented as below :
 a = @browser.td.span(:class => "draggable ui-draggable")
 b = @browser.div(:class => "droparea ui-droppable ui-sortable")
@browser.action.drag_and_drop(a, b).perform

Thanks in-advance.

John Fitisoff

unread,
Jul 8, 2013, 10:53:00 AM7/8/13
to watir-...@googlegroups.com
Think it just needs to be @browser.driver.action... instead of @browser.action...





Sent: Monday, July 8, 2013 6:53 AM
Subject: [wtr-general] Re: [Watir-webdriver] - Drag and drop using watir webdriver

Hi,
I've tried but its throwing below error :

      undefined method `action' for #<Watir::Browser:0x3010cf8> (NoMethodError)

I'm using native events and not sure how to use watirwebdriver ActionBuilder.Can anyone help me with this issue ?

Implemented as below :
 a = @browser.td.span(:class => "draggable ui-draggable")
 b = @browser.div(:class => "droparea ui-droppable ui-sortable")
@browser.action.drag_and_drop(a, b).perform

Thanks in-advance.

On Wednesday, July 3, 2013 2:53:28 PM UTC+1, watir webdriver wrote:
Hi there,

I'm trying to drag and drop an element in webpage through the below code:

Step def:
When(/^I drag and drop Basket rule to the position slot$/) do
@browser.span(:class => "draggable ui-draggable").drag_and_drop_ on(@browser.div(:class => "droparea ui-droppable ui-sortable"))

end

The scenario is passing but on the webpage its just high lighting the draggable element.(drop is not working)

HTML code for draggable code:
<tr>
<td>
<span class="draggable ui-draggable" full="Basket" ai d="BASKET"> Basket</span>
</td>
<tr>


HTML code for droppable code:
<div id="0" class="droparea ui-droppable ui-sortable">

Anyone can help me with this issue ?

Thanks in-advance.

watir webdriver

unread,
Jul 8, 2013, 11:01:41 AM7/8/13
to watir-...@googlegroups.com
Thanks for your reply but still its not working...

Error :
      expected Selenium::WebDriver::Element, got #<Watir::Span:0x4efe4392 locate
d=false selector={:class=>"draggable ui-draggable", :tag_name=>"span"}>:Watir::S
pan (TypeError)


Implemented as below :
  a = @browser.span(:class => "draggable ui-draggable")
 b = @browser.div(:class => "droparea ui-droppable ui-sortable")
@browser.driver.action.drag_and_drop(a, b).perform

Your help is much more appreciated.



On Wednesday, July 3, 2013 2:53:28 PM UTC+1, watir webdriver wrote:

John Fitisoff

unread,
Jul 8, 2013, 11:15:36 AM7/8/13
to watir-...@googlegroups.com
That's because it's looking for a Selenium::Webdriver::Object and the calls to  @browser.span and @browser.div are returning Watir::Span and Watir::Div objects. Think you just need to use @b.find_element to populate vars a and b and then it should work




Sent: Monday, July 8, 2013 8:01 AM

Subject: [wtr-general] Re: [Watir-webdriver] - Drag and drop using watir webdriver
Thanks for your reply but still its not working...

Error :
      expected Selenium::WebDriver::Element, got #<Watir::Span:0x4efe4392 locate
d=false selector={:class=>"draggable ui-draggable", :tag_name=>"span"}>:Watir::S
pan (TypeError)


Implemented as below :
  a = @browser.span(:class => "draggable ui-draggable")
 b = @browser.div(:class => "droparea ui-droppable ui-sortable")
@browser.driver.action.drag_and_drop(a, b).perform

Your help is much more appreciated.


On Wednesday, July 3, 2013 2:53:28 PM UTC+1, watir webdriver wrote:
Hi there,

I'm trying to drag and drop an element in webpage through the below code:

Step def:
When(/^I drag and drop Basket rule to the position slot$/) do
@browser.span(:class => "draggable ui-draggable").drag_and_drop_ on(@browser.div(:class => "droparea ui-droppable ui-sortable"))

end

The scenario is passing but on the webpage its just high lighting the draggable element.(drop is not working)

HTML code for draggable code:
<tr>
<td>
<span class="draggable ui-draggable" full="Basket" ai d="BASKET"> Basket</span>
</td>
<tr>


HTML code for droppable code:
<div id="0" class="droparea ui-droppable ui-sortable">

Anyone can help me with this issue ?

Thanks in-advance.

watir webdriver

unread,
Jul 8, 2013, 12:33:58 PM7/8/13
to watir-...@googlegroups.com
Still no luck...
Implemented as below :
 a = @browser.span(:text => "Abandoned Basket").wd
 b = @browser.div(:class => "droparea ui-droppable ui-sortable").wd
@browser.driver.action.drag_and_drop(a,b).perform

The scenario is just passing successfully but its not meeting the expected result of dragging and dropping the element.I've checked manually by visiting the page.

Thanks in-advance.



On Wednesday, July 3, 2013 2:53:28 PM UTC+1, watir webdriver wrote:

John Fitisoff

unread,
Jul 8, 2013, 1:21:01 PM7/8/13
to watir-...@googlegroups.com
That seems right. The only other thing I can think of is to break the interaction down further and add pauses between each action (do click_and_hold, move_to and release methods in ActionBuilder). And it probably makes sense to do it manually through a console, using irb or pry. Maybe someone else with lots of drag and drop experience has some other idea. I've only used it a little.

It's probably also worth trying things in different browsers in case there's some driver-specific problem.






Sent: Monday, July 8, 2013 9:33 AM

Subject: [wtr-general] Re: [Watir-webdriver] - Drag and drop using watir webdriver
Still no luck...
Implemented as below :
 a = @browser.span(:text => "Abandoned Basket").wd
 b = @browser.div(:class => "droparea ui-droppable ui-sortable").wd
@browser.driver.action.drag_and_drop(a,b).perform

The scenario is just passing successfully but its not meeting the expected result of dragging and dropping the element.I've checked manually by visiting the page.

Thanks in-advance.


On Wednesday, July 3, 2013 2:53:28 PM UTC+1, watir webdriver wrote:
Hi there,

I'm trying to drag and drop an element in webpage through the below code:

Step def:
When(/^I drag and drop Basket rule to the position slot$/) do
@browser.span(:class => "draggable ui-draggable").drag_and_drop_ on(@browser.div(:class => "droparea ui-droppable ui-sortable"))

end

The scenario is passing but on the webpage its just high lighting the draggable element.(drop is not working)

HTML code for draggable code:
<tr>
<td>
<span class="draggable ui-draggable" full="Basket" ai d="BASKET"> Basket</span>
</td>
<tr>


HTML code for droppable code:
<div id="0" class="droparea ui-droppable ui-sortable">

Anyone can help me with this issue ?

Thanks in-advance.

watir webdriver

unread,
Jul 10, 2013, 6:43:33 AM7/10/13
to watir-...@googlegroups.com
Thanks for your reply...with this code I can see the drag and drop but after couple of seconds the dropped element is getting disappeared...but the scenario is passed successfully...Although it didn't work as expected when I checked manually by visiting the webpage.Any one can help me with this ?

my_element = @browser.span(:text => "Abandoned Basket")
target = @browser.div(:class => "droparea ui-droppable ui-sortable")
target = @browser.div(:id => "0")
my_element.fire_event("onmousedown")
@browser.driver.action.click_and_hold(my_element.wd).perform
sleep 15
@browser.driver.action.move_to(target.wd).perform
sleep 15
my_element.fire_event("onmouseup")
end


Your help is much more appreciated.


On Wednesday, July 3, 2013 2:53:28 PM UTC+1, watir webdriver wrote:

John Fitisoff

unread,
Jul 10, 2013, 1:00:56 PM7/10/13
to watir-...@googlegroups.com
A couple of seconds seems like a long time. Maybe try the action builder 'release' action instead of firing the event? Maybe some javascript event isn't occurring at the right time? One thing that really helps me is to use pry to stop the test right at the point that the problem is occurring (maybe you're already doing something like that). Then it's a lot easier to see what's going on. You can just install pry and then insert binding.pry at the point where you want the test to halt. Then type exit to continue execution.



Sent: Wednesday, July 10, 2013 3:43 AM

Subject: [wtr-general] Re: [Watir-webdriver] - Drag and drop using watir webdriver
Thanks for your reply...with this code I can see the drag and drop but after couple of seconds the dropped element is getting disappeared...but the scenario is passed successfully...Although it didn't work as expected when I checked manually by visiting the webpage.Any one can help me with this ?

my_element = @browser.span(:text => "Abandoned Basket")
target = @browser.div(:class => "droparea ui-droppable ui-sortable")
target = @browser.div(:id => "0")
my_element.fire_event("onmousedown")
@browser.driver.action.click_and_hold(my_element.wd).perform
sleep 15
@browser.driver.action.move_to(target.wd).perform
sleep 15
my_element.fire_event("onmouseup")
end

Your help is much more appreciated.


On Wednesday, July 3, 2013 2:53:28 PM UTC+1, watir webdriver wrote:
Hi there,

I'm trying to drag and drop an element in webpage through the below code:

Step def:
When(/^I drag and drop Basket rule to the position slot$/) do
@browser.span(:class => "draggable ui-draggable").drag_and_drop_ on(@browser.div(:class => "droparea ui-droppable ui-sortable"))

end

The scenario is passing but on the webpage its just high lighting the draggable element.(drop is not working)

HTML code for draggable code:
<tr>
<td>
<span class="draggable ui-draggable" full="Basket" ai d="BASKET"> Basket</span>
</td>
<tr>


HTML code for droppable code:
<div id="0" class="droparea ui-droppable ui-sortable">

Anyone can help me with this issue ?

Thanks in-advance.

watir webdriver

unread,
Jul 11, 2013, 1:37:53 PM7/11/13
to watir-...@googlegroups.com
Thanks for the reply John...I've managed to fix the issue.
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/mrHJU9iGIqI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.

watir webdriver

unread,
Jul 14, 2013, 11:29:45 AM7/14/13
to watir-...@googlegroups.com
Thanks for the reply John...I've managed to fix the issue.

On Wednesday, July 10, 2013, John Fitisoff wrote:
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/mrHJU9iGIqI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.

John Fitisoff

unread,
Jul 14, 2013, 1:44:41 PM7/14/13
to watir-...@googlegroups.com
Oh, good!



From: watir webdriver <watirweb...@gmail.com>
To: "watir-...@googlegroups.com" <watir-...@googlegroups.com>
Sent: Sunday, July 14, 2013 8:29 AM
Subject: Re: [wtr-general] [Watir-webdriver] - Drag and drop using watir webdriver

Chuck van der Linden

unread,
Aug 5, 2013, 1:32:05 PM8/5/13
to watir-...@googlegroups.com
On Sunday, July 14, 2013 8:29:45 AM UTC-7, watir webdriver wrote:
Thanks for the reply John...I've managed to fix the issue.

So for the benefit of anyone else who is trying to do this sort of thing, would you care to share with us HOW you managed to fix the issue, e.g. the code that is working to do what you wanted?

 

 
---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscribe@googlegroups.com

 
---
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/mrHJU9iGIqI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to watir-general+unsubscribe@googlegroups.com.

watir webdriver

unread,
Aug 14, 2013, 6:05:32 AM8/14/13
to watir-...@googlegroups.com
I've used the below code and it worked....

 my_element1 = @browser.span(:text => abc)
  target1 = @browser.div(:class => "droparea ui-droppable ui-sortable")
  my_element1.fire_event("onmousedown")
    @browser.driver.action.click_and_hold(my_element1.wd).perform
    sleep 10
    @browser.driver.action.move_to(target1.wd).click.perform
    sleep 5
    my_element1.fire_event("onmouseup")

Thanks.


On Wednesday, July 3, 2013 2:53:28 PM UTC+1, watir webdriver wrote:
Reply all
Reply to author
Forward
0 new messages