0

I am working on a test, where I am trying to utilize drag and drop to drag the 'Text' from grapejs editor into the Frame, where we enter in our content.

I first tried to move the element from one element to the other, but I noticed that the second element was within an iframe, so I tried to use the x, y coordinates. But of course, the XY coordinates are (0,0) within the frame. So the element was out of range. I also tried the 0,0, but also said it was out of bounds.

  var target = Driver.Instance.FindElement(By.XPath("//*[@id='gjs']/div[1]/div[2]/div[5]/div[2]/div/div[1]/div[1]/div[2]/div[5]"));
  var builder = new Actions(Driver.Instance);
  var action = builder.ClickAndHold(target);
  builder.Build();
  action.Perform();
  var iframe = Driver.Instance.FindElement(By.TagName("iframe"));
  Driver.Instance.SwitchTo().Frame(iframe);

  builder = new Actions(Driver.Instance);
  var destination = Driver.Instance.FindElement(By.XPath("/html/body"));
  action = builder.MoveToElement(destination);
  builder.Release(destination);
  builder.Build();
  action.Perform();

Has anyone successfully used Selenium to Drag and Drop across to an iframe lately? All the examples are old...maybe there is a new way to do it. All the examples say use the offset, but putting what I think is the offset for that iframe in the page is not working, nor is switching to the iframe, and setting the co-ordinates within the frame.

Greg P
  • 772
  • 2
  • 10
  • 23
  • Hope this will help you - https://stackoverflow.com/questions/11897385/how-to-perform-drag-and-drop-using-selenium-webdriver-when-target-and-destinatio – Abhishek Dhoundiyal Jul 27 '21 at 13:02
  • oh wow, didn't think of doing something like this..I will try and mark this as the answer if (or should I say when)..this works. – Greg P Jul 27 '21 at 13:07
  • Unfortunately it didn't work. It says that move target out of bounds. Updating main post with updated code. – Greg P Jul 27 '21 at 13:43
  • @GregP can you share the URL? – YaDav MaNish Jul 27 '21 at 13:57
  • We are using grapejs..on a private site...but here is the homepage of grapejs.. https://grapesjs.com/demo.html, where I am trying to drag "Typed", to the body on the left. – Greg P Jul 27 '21 at 15:35
  • 1
    @GregP this same question is asked here https://stackoverflow.com/questions/61053232/how-to-move-drag-element-from-outside-to-iframe – YaDav MaNish Jul 27 '21 at 17:45
  • Yes, you are right... great, I got to work with sending javascript functions. I will go down that route. Thank you. – Greg P Jul 27 '21 at 18:11

0 Answers0