3

I am automating drag and drop using Selenium and Java. Following is the code used for performing drag and drop using chrome driver in headless mode.

Point classname = targetElement.getLocation();
int xcordi = classname.getX();
int ycordi = classname.getY();
Actions action = new Actions(driver);
action.clickAndHold(sourceElement).moveByOffset(xcordi, ycordi).release(targetElement).build().perform();

Nothing happens when this is executed in headless chrome driver. However, in non-headless chrome driver, this works fine and drag and drop is performed.

Note - Tried using both dragAndDropBy(source, target) and dragAndDropBy(source, xOffset, yOffset). Both of these methods are not working in non-headless chrome as well

2

2 Answers 2

1

I don't think we can help you debug a difference between the Chrome browser versus the headless version. I do not think it is a known issue and there is no known work-around.

A suggestion:

  1. Create a minimal test with HTML code with which you can proof dragAndDrop fails only headless, publish it publicly.
  2. Afterwards Create a chromium bug: https://www.chromium.org/for-testers/bug-reporting-guidelines
  3. Ask for support from the headless mailing list, linking to your example failing test: https://groups.google.com/a/chromium.org/forum/#!forum/headless-dev

Maybe in the creation of your minimal test, you will figure out why it does work, but not for your specific case. The application behaves differently headless instead of the browser :)

-1

HtmlUnit is a GUI-Less browser for Java programs that can do a lot for us, but not everything. And, as you have noticed, it has no support for operations such as drag and drop

new UnsupportedOperationException("Moving to arbitrary X,Y coordinates not supported.");

contrary to other Selenium drivers, like selenium-chromedriver, in which one your example should work fine.

However, if you still need it to work with a headless web testing, there's an option with PhantomJS. Yes, it is focused for JS testing, but there is a great project called Ghost Driver (a implementation of Webdriver Wire protocol in simple JS for PhantomJS) that enables Java bindings along with Selenium API

1

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.