Skip to content

[py] ActionChains.drag_and_drop_by_offset moving to absolute position #6171

@Herst

Description

@Herst

Meta -

OS: Linux

Selenium Version: 3.13.0

Expected Behavior -

ActionChains.drag_and_drop_by_offset not being broken as described below, where instead of moving by an offset it might try to move by to a viewport location.

Actual Behavior -

For ActionChains.drag_and_drop_by_offset selenium tries to move the pointer to an absolute instead of a relative position when using a W3C driver, that's why e.g. when testing with Firefox you get a MoveTargetOutOfBoundsException when trying to move to the offset (-10, -10).

def drag_and_drop_by_offset(self, source, xoffset, yoffset):
    """
    Holds down the left mouse button on the source element,
       then moves to the target offset and releases the mouse button.

    :Args:
     - source: The element to mouse down.
     - xoffset: X offset to move to.
     - yoffset: Y offset to move to.
    """
    if self._driver.w3c:
        self.w3c_actions.pointer_action.click_and_hold(source) \
                                       .move_to_location(xoffset, yoffset) \
                                       .release()
        for _ in range(3):
            self.w3c_actions.key_action.pause()
    else:
        self.click_and_hold(source)
        self.move_by_offset(xoffset, yoffset)
        self.release()
    return self

PointerActions.move_to_location:

def move_to_location(self, x, y):
    self.source.create_pointer_move(origin='viewport', x=int(x), y=int(y))
    return self

As you can see, it is meant for absolute positions.

Steps to reproduce -

Code such as:

ActionChains(driver)\
     .drag_and_drop_by_offset(element, -10, -10)\
     .perform()

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-pyPython Bindings

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions