Prawn · Proxy server -- Registry · ramaze · random names

Drag and Drop using Watir-webdriver

Requirement :

Drag and Drop an element to the particular location

Code:
require 'rubygems'
require ‘watir-webdriver’

browser=Watir::Browser.new :ie
browser.goto("http://devfiles.myopera.com/articles/735/example.html")

my_element=browser.li(:text,'Art Brut')
target=browser.ul(:id,'Rej').li(:text,'None')

my_element.fire_event("onmousedown")

driver=browser.driver
driver.action.click_and_hold(my_element.wd).perform

sleep 2
driver.action.move_to(target.wd).perform

sleep 2
target.fire_event("onmouseup")

Advertisements

2 thoughts on “Drag and Drop using Watir-webdriver

  1. I’m trying to drag and drop an element in webpage through the below 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.Can you plz help?

    When(/^I drag and drop Abandoned Basket rule to the position slot on the emailcreate page$/) do

    my_element = @browser.span(:text => “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
    target.fire_event(“onmouseup”)

    end

    HTML code for draggable code:

    Basket

    HTML code for droppable code:

    I’m using BDD framework (Ruby+cucumber).

    Thanks in-advance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s