Selenium MouseDownAt MouseMoveAt and MouseUpAt example 

Here is an example that tells you how you can use Selenium MouseDownAt MouseMoveAt and MouseUpAt commands to do drag an item from one location and drop the item in another location. I am using the Drag & Drop: Reordering a List example Yahoo Developer Network.
Here is the url for the drag and drop example – http://developer.yahoo.com/yui/examples/dragdrop/dd-reorder.html


using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace SeleniumTests
{
[TestFixture]
public class Untitled
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://developer.yahoo.com");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheUntitledTest()
{
selenium.Open("/yui/examples/dragdrop/dd-reorder.html");
selenium.Click("//input[@id='switchButton']");
selenium.MouseDownAt("//li[@id='li1_1']", "");
Thread.Sleep(5000);
selenium.MouseMoveAt("//div[@id='example-canvas']/div[@class='workarea'][2]/ul", "");
Thread.Sleep(5000);
selenium.MouseUpAt("//div[@id='example-canvas']/div[@class='workarea'][2]/ul", "");
}
}
}

If you found this solution helpful or have something extra to add, feel free to share it here by commenting below.


Selenium Webdriver Forum -The Online Community for Selenium Webdriver and Selenium RC Users and Professionals
2 responses to “Selenium MouseDownAt MouseMoveAt and MouseUpAt example”
  1. Luke Griffiths says:

    Thanks Pavandeep, this is just what I was looking for. Let’s see if it works now …

  2. Mani says:

    Hi,

    I want to automate the testing of canvas element using selenium…I have tried couple of methods…But, none seemed to work..I am trying for digital signature…Can you please provide some suggestions?

    Thanks,

    Mani

Leave a Reply