I tried to drag to drop an element from a frame to a non-frame. I know this is a repetitive question in StackOverflow, but I did not get any correct answer for the same question. Requesting your help on the same.

Code used:

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class DragDropIframes {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        WebDriverWait wait = new WebDriverWait(driver, 30);
        WebElement drag = driver.findElement(By.className("adcontainer"));
        WebElement drop = driver.findElement(By.id("q"));
        Actions a1 = new Actions(driver);
        Actions a2 = a1.clickAndHold(drag);
        Actions a3 =a1.moveToElement(drop).release(drop);

Error message:

Exception in thread "main" org.openqa.selenium.WebDriverException: UnknownError: Cannot release a button when no button is pressed.'UnknownError: Cannot release a button when no button is pressed.' when calling method: [wdIMouse:: up]
Command duration or timeout: 343 milliseconds

3 Answers 3


Selenese is a flavour of Javascript which has a "Same Origin Policy" security restriction. If your frames are from different websites, dragging/dropping between the two would violate the Same Origin Policy and not be allowed.

One answer can be found here.

If you're not married to Selenium, another way to sidestep the Same Origin Policy restriction is to use Sikuli. Sikuli is an open-source java-based cross-platform record/playback tool that uses object recognition instead of object names. If you can see it on the screen, you can automate it. It's not a magic pill that will solve all your automation problems, but it might be helpful here.


another way to sidestep the Same Origin Policy restriction is to use Sikuli.

Another object recognition based solution is to use the free Kantu Visual Testing app. It works just like Sikuli, but inside a Chromium web browser. Since it works "inside" Chromium, you can run many tests at once, and run it headless.


Irrespective of the structure of frames, one can always use Robot class to drag and drop elements across them. I am providing a sample code just in case:

//Setting up chrome driver
WebDriver driver = new ChromeDriver();

//Redirecting to the website

Robot robot = new Robot();
robot.mouseMove(x-coordinate1, y-coordinate1);

robot.mouseMove(x-coordinate2, y-coordinate2);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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