Skip to content

Drag and Drop problem (Pointer.down() / Pointer.up()) #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Acanis87 opened this issue Nov 6, 2024 · 1 comment
Open

Drag and Drop problem (Pointer.down() / Pointer.up()) #278

Acanis87 opened this issue Nov 6, 2024 · 1 comment
Labels
good first issue Good for newcomers unconfirmed a bug which hasn't been reproduced yet

Comments

@Acanis87
Copy link

Acanis87 commented Nov 6, 2024

Hey,

as already shared in Discord, Iam not able to create a Drag and Drop movement. Maybe I do something wrong, but the documentation didnt really help me there, for up() and down() it just asks for (**kwargs).

I made a small example of the problem and of what I tried:

import asyncio
from selenium_driverless import webdriver

async def test_drag_and_drop():
    # Create driver
    driver = await webdriver.Chrome()
    try:
        # Navigate to test page
        await driver.get("https://kaliiiiiiiiii.github.io/Selenium-Driverless/index.html")
        await asyncio.sleep(1)  # Wait for page load

        # Find source and target elements
        source_element = await driver.find_element(
            "xpath",
            "//div[@class='wy-menu wy-menu-vertical']//a[@href='api/WebELement.html']"
        )
        target_element = await driver.find_element(
            "xpath",
            "//*[@id='rtd-search-form']"
        )
        if not source_element or not target_element:
            print("Could not find required elements")
            return

        print("Calculating element positions...")
        source_pos = await source_element.mid_location()
        target_pos = await target_element.mid_location()
        print(f"Source position: {source_pos}")
        print(f"Target position: {target_pos}")

        pointer = driver.current_pointer

        # Variant 1: No arguments for down/up
        print("\nTesting Variant 1: down()/up() without arguments")
        try:
            await pointer.move_to(source_pos[0], source_pos[1])
            await driver.sleep(0.2)
            await pointer.down()  # No arguments
            await driver.sleep(0.2)
            await pointer.move_to(target_pos[0], target_pos[1])
            await driver.sleep(0.2)
            await pointer.up()  # No arguments
            print("Variant 1 completed")
        except Exception as e:
            print(f"Variant 1 error: {e}")

        await asyncio.sleep(1)

        # Variant 2: Complete tuple from mid_location
        print("\nTesting Variant 2: down()/up() with complete tuple")
        try:
            await pointer.move_to(source_pos[0], source_pos[1])
            await driver.sleep(0.2)
            await pointer.down(source_pos)  # Complete tuple
            await driver.sleep(0.2)
            await pointer.move_to(target_pos[0], target_pos[1])
            await driver.sleep(0.2)
            await pointer.up(target_pos)  # Complete tuple
            print("Variant 2 completed")
        except Exception as e:
            print(f"Variant 2 error: {e}")

        await asyncio.sleep(1)

        # Variant 3: Separate x,y coordinates from mid_location
        print("\nTesting Variant 3: down()/up() with separate x,y coordinates")
        try:
            await pointer.move_to(source_pos[0], source_pos[1])
            await driver.sleep(0.2)
            await pointer.down(source_pos[0], source_pos[1])  # Separate coordinates
            await driver.sleep(0.2)
            await pointer.move_to(target_pos[0], target_pos[1])
            await driver.sleep(0.2)
            await pointer.up(target_pos[0], target_pos[1])  # Separate coordinates
            print("Variant 3 completed")
        except Exception as e:
            print(f"Variant 3 error: {e}")

        await asyncio.sleep(2)  # Wait to see the results

    finally:
        await driver.quit()

if __name__ == "__main__":
    asyncio.run(test_drag_and_drop())

Result:

Calculating element positions...
Source position: [133, 327]
Target position: [210, 62]

Testing Variant 1: down()/up() without arguments
Variant 1 error: PointerEvent.init() missing 2 required positional arguments: 'x' and 'y'

Testing Variant 2: down()/up() with complete tuple
Variant 2 error: Pointer.down() takes 1 positional argument but 2 were given

Testing Variant 3: down()/up() with separate x,y coordinates
Variant 3 error: Pointer.down() takes 1 positional argument but 3 were given

Process finished with exit code 0

I think it would be great to add a Pointer.drag_n_drop() with a start element (or coordinate) and end element (or coordinate). I hope you can fix the bug or tell me, when it was my fault ^^

@kaliiiiiiiiii kaliiiiiiiiii added good first issue Good for newcomers unconfirmed a bug which hasn't been reproduced yet labels Nov 6, 2024
@kaliiiiiiiiii
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers unconfirmed a bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

2 participants