How to perform drag and drop using selenium-webdriver when target and destination element are in different frames?

Viewed 26611

I have to drag an image and drop it into a CQ5 component. The image and component are in different frames.

Here is the code which did not work as webelement destinationcould not be found when the target's frame was active.

new Actions(driver).dragAndDrop(target, destination).perform();

I have also tried to switch frame in between action as:

    Actions builder = new Actions(driver);
    Actions action = builder.clickAndHold(target);
    driver.switchTo().frame("newFrame"); //switching frames
    builder.moveToElement(destination);
    builder.release(destination);
    builder.build();
    action.perform();

This is did not work either. Then, I tried moving the image by offset

new Actions(driver).dragAndDropBy(target,  x, y).perform(); // x and y 

This moved the image but component did not capture it, probably becuase action was too fast. Is there any way such drag drop can be done?

Thanks in advance.

11 Answers
Related