-
Notifications
You must be signed in to change notification settings - Fork 678
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
How to drag and drop an item? For eg an image on powerpoint slide #58
Comments
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 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. |
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() |
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. |
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 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() |
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. |
raising from user query in #57 (comment)
The text was updated successfully, but these errors were encountered: