Drag and Drop random region

Asked by xyz_User on 2020-05-01

Would appreciate if someone can show me how drag and drop would work via random screen regions.

I have it specify manual coords to do it - And it works, but how can I make so it's completely random and not dependent on manual coords that I provide, this is what I have:

def randomDrag1():
 dragDrop(Location(214, 771),Location(1464, 151))
def randomDrag2():
 dragDrop(Location(1457,148),Location(308,798))
def randomDrag3():
 dragDrop(Location(217,236),Location(1543,823))

def randomChoice():
    all3Locations = [randomDrag1, randomDrag2, randomDrag3]
    random.choice(all3Locations)()

randomChoice()

Thank you!

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
2020-05-02
Last query:
2020-05-02
Last reply:
2020-05-02
Manfred Hampl (m-hampl) said : #1

Probably something like

import random
random.seed()

mywidth = Screen(0).getW()
myheight = Screen(0).getH()

dragDrop(Location(random.randint(0,mywidth),random.randint(0,myheight)),Location(random.randint(0,mywidth),random.randint(0,myheight)))

xyz_User (userseven) said : #2

Thank you Manfred, I'd like to specify about 80% of the screen (or a region) and not the entire full screen. If that makes sense

Best Manfred Hampl (m-hampl) said : #3

Just a small modification, I had expected that you can do the required changes yourself.
Probably something like

import random
random.seed()

myRegion = ... # define your region by whatever means, e.g. by specifying the coordinates, or as a match for a find action, ...

myX = myRegion.getX()
myY = myRegion.getY()
myW = myRegion.getW()
myH = myRegion.getH()

dragDrop(Location(random.randint(myX,myX+myW),random.randint(myY,myY+myH)), Location(random.randint(myX,myX+myW),random.randint(myY,myY+myH)))

xyz_User (userseven) said : #4

Thanks very much Manfred!

xyz_User (userseven) said : #5

Thanks Manfred Hampl, that solved my question.