Skip to content

How to drag and drop an item? For eg an image on powerpoint slide #58

Closed

Description

@kensoh

raising from user query in #57 (comment)

Activity

  1. kensoh commented on Sep 17, 2019

    @kensoh
    MemberAuthor

    There are usually various ways to get to the same outcome. Try to think of how something is done manually, and then map that series of actions to the UI interaction functions in this tool.

    In this case, maybe doing a r.click('image.png') and then doing a r.keyboard('[left][left][left][left][left][left][left][left][left][left][left][left]') can give desired outcome.

    Or maybe doing something below to drag and drop left by 100 pixels works?

    r.click('image.png')
    r.mouse('down')
    r.hover(r.mouse_x() - 100, r.mouse_y())
    r.mouse('up')

    If above works but too many lines of code, you can write your own Python function to combine the above steps to do what you need, so that you only need to write 1 line to do this action.

  2. kensoh commented on Sep 18, 2019

    @kensoh
    MemberAuthor

    Below is an example (for first action, hover will do) -

    import rpa as r
    r.init(True)
    
    def dragdrop(element_identifier, x_offset, y_offset):
        r.hover(element_identifier)
        r.mouse('down')
        r.hover(r.mouse_x() + x_offset, r.mouse_y() + y_offset)
        r.mouse('up')
    
    dragdrop('a.png', -200, 0)
    r.close()
  3. kensoh commented on Sep 19, 2019

    @kensoh
    MemberAuthor

    Closing issue for now as the implementation should be quite straight forward, the challenge is figuring out the step by step details how a human user manually do the sequence of actions to get it done. Then map to above type of Python code.

  4. changed the title [-]How to drag an item to the left? For eg an image on powerpoint slide[/-] [+]How to drag and drop an item? For eg an image on powerpoint slide[/+] on Jan 4, 2020
  5. kensoh commented on Jan 4, 2020

    @kensoh
    MemberAuthor

    Adding on to above sample code which drags and drops by coordinates offset, below sample drags and drops from a source image identifier to a target image identifier using visual automation -

    import rpa as r
    r.init(True)
    
    def dragdrop(source_identifier, target_identifier):
        r.hover(source_identifier)
        r.mouse('down')
        r.hover(target_identifier)
        r.mouse('up')
    
    dragdrop('a.png', 'b.png')
    r.close()

    You can also create a function to drag and drop from the source to the target x,y coordinates -

    import rpa as r
    r.init(True)
    
    def dragdrop(source_x, source_y, target_x, target_y):
        r.hover(source_x, source_y)
        r.mouse('down')
        r.hover(target_x, target_y)
        r.mouse('up')
    
    dragdrop(200, 100, 600, 200)
    r.close()

    If you prefer to keep syntax consistent as r.dragdrop() you can define and map it as follows -

    import rpa as r
    r.init(True)
    
    # define the dragdrop() function
    def dragdrop(source_x, source_y, target_x, target_y):
        r.hover(source_x, source_y)
        r.mouse('down')
        r.hover(target_x, target_y)
        r.mouse('up')
    
    # map the function to r object
    r.dragdrop = dragdrop
    
    # invoke using r.dragdrop()
    r.dragdrop(200, 100, 600, 200)
    r.close()
  6. kensoh commented on Jan 4, 2020

    @kensoh
    MemberAuthor

    I'm leaving a dragdrop() or drag() function out from API because it may not be that commonly used and can clutter up the API which contains the essentials plus some pros functions. But if there are users interested and often use something like this I can add a new function into basic functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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