5

Using the Python bindings of Selenium Webdriver, I cannot get drag-and-drop working on a "complex" jQuery UI example with ActionChains.drag_and_drop(). (It does work on a simple example.)

My testing indicates that release(target) is failing, not click_and_hold(source). A PasteBin example of my problem is available here.

I feel somewhat powerless when things do not work in WebDriver. How should I go about debugging this?

asked Jan 20, 2012 at 16:04
5
  • Which exception/error occurs when failing? Commented Jan 21, 2012 at 18:34
  • @xeranas: The weird thing is that no error happens. I simply do not see any effect of the drag-and-drop: the draggable element doesn't get dragged! Commented Jan 21, 2012 at 23:25
  • please make sure you give details when you ask a question. It's difficult for us to understand what your "simple" code looks like or what your "more complex" code looks like. Commented Jan 22, 2012 at 3:08
  • @xeranas: I've added a simplified version of my code in a pastebin here. Commented Jan 23, 2012 at 12:30
  • @MacGyver: I rewrote the question, with a link to an example. Commented Jan 23, 2012 at 12:49

2 Answers 2

5
+50

If it's ChromeDriver, I had the same problem. Turns out you have to insert a dummy drag operation in between, like so:

 Actions builder = new Actions(GuiOps.driver);
 // Click and hold fromElem
 builder = builder.ClickAndHold(fromElem);
 // If this is Chrome, insert a tiny move-by-offset call.
 // See http://code.google.com/p/chromium/issues/detail?id=92312 for more details.
 if (driver is OpenQA.Selenium.Chrome.ChromeDriver)
 {
 builder = builder.MoveByOffset(1, 1);
 }
 // Then move to the target and release:
 builder.MoveToElement(toElem, offsetX, offsetY).Release().Build().Perform();
answered Jan 25, 2012 at 18:32
4

I see you are using chromeDriver. There are more unsolved questions: "Drag-and-drop with ChromeDriver", "Python Selenium WebDriver drag-and-drop" so if you can not find problem, maybe it at this time unsolvable then I suggest try run test with different browser.

As always you should be 100% sure that for drag_and_drop method you give correct parameters. I see you check visibility but to be sure I recommend two things:

  • sleep(15) before actionChains.drag_and_drop. I use sleep method only for debug purpose. If it works with long sleep then it means that methods like waitForElement or waitForPageLoad is incorrectly implemented (need improve).
  • print out in console info about drag_and_drop source and targer objects just before it uses as parameters. Try print out tag name, id, class or something which make sure that correct elements are used.

You mentioned that Web Application based UI based complex jQuery methods, which means that it can have such functions like change DIV backgrounds when mouse is over or something like that. It can even change DIV element class names, size or other css property which can lead your drag_and_drop target object different than it was before you start drag it. You can try debug what happens to target element when mouse is over move_to_element print out info about mouse_on_target element object, compare with target_before_mouse_on object. Even if object mouse_on_target did't changed something on parent element can be changed. In this case Java trows special exception InvalidElementStateException when I try use such element. However I do not know how python react in mentioned case. You can try test with entering target coordinates manually using drag_and_drop_by_offset (see on documentation) . With this method at least you will know on which place it try release target.

answered Jan 24, 2012 at 11:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.