0

I am trying to drag and drop an object on Safari 12.1 On Mac Os Hi Sierra.

It Drags the object, moves to the specified location, but it does not release the object.

I executed the lines of code mentioned below but both of them had the same effect:

actionTest.dragAndDropBy(dragMe,
xCoOrdinate,yCoOrdinate).build().perform();

actionTest.dragAndDropBy(dragMe,
xCoOrdinate,yCoOrdinate).release().build().perform();

Please advice if I need to set any browser capabilities.

The Test Url used is: https://www.bryntum.com/examples/scheduler/animations/

Please see "Import Meeting" in the screenshot.

jhpratt
  • 6,841
  • 16
  • 40
  • 50
Harish
  • 11
  • 8
  • Try this:-`WebElement From=driver.findElement(By.xpath("//*[@id=\"b-scheduler-8-1-1-x\"]/div"));` `WebElement To=driver.findElement(By.xpath("//*[@id=\"b-subgrid-14\"]/div[2]/div")); ` `Actions act=new Actions(driver);` `act.dragAndDrop(From, To).build().perform(); ` – Pradnya Bolli Apr 09 '19 at 12:27
  • @PradnyaBolli tried this didnt work, failed with no such element exception at the 1st line of ur suggested code, are u setting any browser capabilities?before running the script? – Harish Apr 15 '19 at 07:51
  • after url line wait for loading page. Enter wait functionality...use this link for information ... may be this helps....https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp – Pradnya Bolli Apr 15 '19 at 09:34

1 Answers1

0

Syntax for drag and drop. The Actions class has two methods that support Drag and Drop. Let's study them-

Actions.dragAndDrop(Sourcelocator, Destinationlocator)

In some applications, we may face a situation to automate drag and drop an item from one location to another location. We could not achieve these using basic elements. Selenium has provided an “Actions” class to handle this kind of scenarios. We overcome this kind of scenarios such as drag and drop using Actions Class.

Action Class in Selenium

In dragAndDrop method, we pass the two parameters -

First parameter "Sourcelocator" is the element which we need to drag.

Second parameter "Destinationlocator" is the element on which we need to drop the first element

Actions.dragAndDropBy(Sourcelocator, x-axis pixel of Destinationlocator, y-axis pixel of Destinationlocator)

dragAndDropBy method we pass the 3 parameters -

  1. First parameter "Sourcelocator" is the element which we need to drag.
  2. The second parameter is x-axis pixel value of the 2nd element on which we need to drop the first element.
  3. The third parameter is y-axis pixel value of the 2nd element on which we need to drop the first element.

You also get more information from this site.

Try This:-

    WebDriver driver= new FirefoxDriver();
    driver.get("https://www.bryntum.com/examples/scheduler/animations/");
    //driver.get("https://demoqa.com/droppable/");
    WebElement From=driver.findElement(By.xpath("//*[@id=\"b-scheduler-8-1-1-x\"]/div"));   

    WebElement To=driver.findElement(By.xpath("//*[@id=\"b-subgrid-14\"]/div[2]/div")); 
    Actions act=new Actions(driver);                    

    //Dragged and dropped.      
         act.dragAndDrop(From, To).build().perform();   

Hope it will work for you..

And for no such element go throgh this link.

Pradnya Bolli
  • 1,915
  • 1
  • 19
  • 37