question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extend dragAndDrop command to allow offset values

See original GitHub issue

Is your feature request related to a problem? Please describe. Currently, dragAndDrop command allows only to move one element to another

$(selector).dragAndDrop(target, duration)

There is no way to move a single element to a certain offset

Describe the solution you’d like

Create a new command dragTo, which performs the same actions, but allows to specify offset, instead of a target selector

$(selector).dragTo(xoffset, yoffset, duration)

Describe alternatives you’ve considered Currently I can implement this myself, using performActions command, but this is not cross-browser and I had to maintain w3c/jsonwp implementations, which is cumbersome.

Having this in the webdriverio library might be useful for somebody.

Additional context I am testing a slider component, which requires dragging interactions, but there is no target element, the slider itself is being dragged. The proposed command could resolve my use-case

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
just-boriscommented, Feb 13, 2020

Here is our custom implementation

const ACTION_BUTTON = 0;
const dragDuration = 100;

async function dragAndDrop(browser, sourceSelector, targetX = 0, targetY = 0) {
        if (!browser.isW3C) {
            const element = await browser.$(sourceSelector);
            await element.moveTo();
            await browser.buttonDown(ACTION_BUTTON);
            await element.moveTo(targetX, targetY);
            await browser.buttonUp(ACTION_BUTTON);
            return;
        }
        const center = await getElementCenter(browser, sourceSelector);
        // W3C way of handle the drag and drop action
        await browser.performActions([
            {
                type: 'pointer',
                id: 'mouse',
                parameters: { pointerType: 'mouse' },
                actions: [
                    { type: 'pointerMove', duration: 0, x: center.x, y: center.y },
                    { type: 'pointerDown', button: ACTION_BUTTON },
                    { type: 'pointerMove', duration: dragDuration, origin: 'pointer', x: targetX, y: targetY },
                    { type: 'pointerUp', button: ACTION_BUTTON }
                ]
            }
        ]);
        // make sure all controls are properly released to avoid conflicts with further actions
        await browser.releaseActions();
    }
0reactions
christian-bromanncommented, Apr 17, 2020

Fixed in #5282

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Drag and Drop in Selenium WebDriver (EXAMPLE)
First parameter “Sourcelocator” is the element which we need to drag · The second parameter is x-axis pixel value of the 2 nd...
Read more >
How to Drag and Drop in Selenium using Action ... - Tools QA
dragAndDropBy(WebElement source, int xOffset, int yOffset): This method clicks & holds the source element and moves by a given offset, then ...
Read more >
dragAndDropToObject - Selenium IDE Commands Tutorial
... column and x,y offset in pixel (Current location to destination location where you want to drop element) in value column with "dragAndDrop"...
Read more >
How to Drag and Drop in Selenium | BrowserStack
This action is performed using a mouse when a user moves (drags) a web element from one location and then places (drops) it...
Read more >
Drag and Drop Action in Selenium webdriver using Actions class
This post will see how to perform Drag and drop in Selenium webdriver.We ca perform Drag and drop in Selenium webdriver using Actions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found