Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I need to automate drag and drop functionality with Telerik controls, I currently use WatiN for my automation (see related quesiton Testing drag-and-drop with Watin on Telerik controls . I am considering if WatiN can't do it, will I able to test drag and drop will if I change to use Selenium 2 instead.

Can this (drag and drop testing in a web applicaiton) be easily achieved with Selenium2 (in C#), ideally without injecting javascript into the application being teseted?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

While I'm not certain if these mechanisms will specifically work with the Telerik controls (I know it works with jQuery), there are a couple of ways to do this. You can use IRenderedWebElement.DragAndDropOn(), but this method is deprecated. The newer way, which isn't available in a released binary form yet, but is checked into the source tree and will be released in the next binary, is to use the Actions class to create the drag-and-drop action. Your code would look something like the following:

public void DragAndDropExample()
{
    // driver is an instance of IWebDriver; 
    // elementToDrag and targetElement are instances of IWebElement
    Actions actionsProvider = new Actions(driver);
    actionsProvider.DragAndDrop(elementToDrag, targetElement).Perform();
}

You can also use the DragAndDropToOffset() method if you want to drag an element to an arbitrary screen location.

share|improve this answer
    
Excellent! This worked for me. Until the recent versions of the FirefoxDriver I had to try and do it with the legacy Selenium driver and mouseDown/mouseMove commands. I am using the offset method now (note the casing is wrong in the sample above - but an IDE editor should be enough to help assist) –  user1416 Oct 6 '11 at 18:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.