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.


2 thoughts on “Selenium MouseDownAt MouseMoveAt and MouseUpAt example

  1. 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

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>