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 destination
could 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.
frame(frameOne); // identify element in first frame WebElement elementOne = driver. findElement(By.id("dragFrame-0")); // Use Actions class for tap and hold Actions actions = new Actions(driver); Actions action = actions. clickAndHold(elementOne); actions. build(); action.
Click And Hold Action: dragAndDrop() method first performs click-and-hold at the location of the source element. Move Mouse Action: Then source element gets moved to the location of the target element. Button Release Action: Finally, it releases the mouse.
I had the same prb as you. I can't darg and drop two elements from one frame to anther. the ansers uppers are correct but from selenium 3 this solution doesn't works any more. The workarrown is to move source element (after clickAndHol) to the positon 0,0 and then to move it under the second frame. for example 150,150.
Actions builder = new Actions(driver);
// switsh to the source frame
driver.switchTo().frame("sourceFrame");
// take the element with mouse
builder.clickAndHold(sourceElt).build().perfom();
// move mouse to the top of the source frame
builder.moveToElement(sourceElt, 0, 0 ).build().perfom();
// move the mouse under the target frame (specific to your case)
builder.moveToElement(sourceElt, 150,200).build().perfom();
// switsh to the target frame
driver.switchTo().frame("targetFrame");
builder.moveToElement(targetElt).build().perform();
builder.release(target).build().perform();
hope I helps you too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With