Skip to content

Not able to drag element using mouse.down and mouse.move #647

@amittendulkar

Description

@amittendulkar

I am trying to drag drop from element1 to element2. This had worked for me with another site. However, I am not able to work it out for the current web application (so my playwright installation or the way of writing script might not be the issue here).

I am using playwright 1.10.0 and using chromium browser.

Here is my sample code,

    page.query_selector(':nth-match(:text("id"), 2)').scroll_into_view_if_needed()
    src_box = page.query_selector('ul.drag-item >> xpath=li[2]').bounding_box()
    tgt_box = page.query_selector('text=ADD VARIABLE').bounding_box()
    mouse: Mouse = page.mouse
    mouse.move(src_box['x']+src_box['width']/2, src_box['y']+src_box['height']/2)
    print('Mouse move')
    mouse.down()
    print('Mouse down')
    mouse.move(tgt_box['x']+tgt_box['width']/2, tgt_box['y']+tgt_box['height']/2, steps=10)
    print('Mouse move with down')
    mouse.up()
    print('Mouse up')
    page.wait_for_selector(':nth-match(:text("id"), 4)')

I can see the mouse pointer changing to draggable mouse pointer. So the source element bounding box coordinates are correct. There is no visible change in the browser indicating the element was dragged.

The script fails on the last line waiting for the 4th match of the 'id' text.

What might be happening here? Any tips?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions