1

Drag and Drop not working..as my drag and drop area not having 'Frames' i didn't use switchTo() here.

    Actions action= new Actions(driver);

    //driver.switchTo().frame(0);

    WebElement drag= driver.findElement(By.xpath("//div[contains(text(),'GEO')]"));

    WebElement drop= driver.findElement(By.xpath("//div[@placeholder='Drag and Drop the subjects which needs evaluation.']"));

    //action.doubleClick(drag);

    Thread.sleep(3000);

    action.dragAndDrop(drag, drop).perform();

    Thread.sleep(3000);

Can anyone please help?

  • You are testing against Chromedriver? If so, try the same test(s) against Firefox. Chromedriver has a known issue with drag-and-drop and HTML5. My HTML5 related elements, I can only drag-n-drop in non-Chrome. github.com/SeleniumHQ/selenium/issues/6235 – Charlie Wilson Feb 23 at 18:56
  • I'm testing on firefox – Albin K S Feb 24 at 5:33
0

You try using build() . Consider the example :

action.dragAndDrop(drag, drop).build().perform();

OR

Try the below code :

new Actions(driver)
                .moveToElement(sourceElement)
                .pause(Duration.ofSeconds(1))
                .clickAndHold(sourceElement)
                .pause(Duration.ofSeconds(1))
                .moveByOffset(2, 0)
                .moveToElement(targetElement)
                .moveByOffset(2,0)
                .pause(Duration.ofSeconds(1))
                .release().build().perform();

Hope it'll resolve the issue

  • I tried both ways but doesn't worked for me – Albin K S Feb 23 at 10:15
  • This answer should work but If its not work I added another answer for this method. – Selçuk Ayhan Feb 26 at 15:24
0

Note: I am adding as an answer since I don't have enough reps to add comment. I will delete the answer if required once the requested change is made.

Albin, is it possible to share the URL where you are facing the issue so we can try ourselves?

Also, a small correction for @jatin khattar. Calling build() is not necessary when using perform(). perform() will call build() method internally. As per the java docs for [Actions][1] class:

void perform()

A convenience method for performing the actions without calling build() first.

Edit: Okay. Sharing the URL is not possible and its understandable. However, can you please share the behaviour when running the code? Any error messages? Or what is happening when the code is executed?

  • so sorry about the URL...it's our upcoming project so that I can't share with anybody..Is there anything else that I can do? – Albin K S Feb 23 at 16:07
0

Can you please try following :

Actions builder = new Actions(driver);

    Action dragAndDrop = builder.clickAndHold(someElement)
       .moveToElement(otherElement)
       .release(otherElement)
       .build();

    dragAndDrop.perform();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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