Drag drop to random (pre-defined) location

Asked by xyz_User on 2019-11-13

Not getting any errors, but also not doing anything. Trying to move an image to a randomly defined coordinate:

import random
from random import choice

def position1():
    position1 = Location(548,292)

def position2():
    position2 = Location(633,293)

def position3():
    position3 = Location(738,288)

def position4():
    position4 = Location(817,284)

def randomDrop():
    positionOneToFour = [position1, position2, position3, position4]
    random.choice(positionOneToFour)()

def main():
    dragDrop("1573618403777.png",(randomDrop))
    print('done')

main()

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
2019-11-13
Last query:
2019-11-13
Last reply:
2019-11-13
xyz_User (userseven) said : #1

@RainMan would really appreciate if you can provide some guidance :)
Thanks

TestMechanic (ndinev) said : #2

You need to fix script like that ( I test it with hover but you can run it with your drag-drop)

import random
from random import choice

def position1():
    return Location(548,292)

def position2():
    return Location(633,293)

def position3():
    return Location(738,288)

def position4():
    return Location(817,284)

def randomDrop():
    positionOneToFour = [position1(), position2(), position3(), position4()]
    return random.choice(positionOneToFour)

def main():
    hover(randomDrop())
    print('done')

main()

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

Have you tried

dragDrop("1573618403777.png",randomDrop()).

(note the position of the left parenthesis)

TestMechanic (ndinev) said : #5

You are calling method incorrectly - you need
1. use () in functions call
2. use return

I example that i gave you i added ()
hover(randomDrop())

so you need to type randomDrop() instead of randomDrop in your dragDrop call

TestMechanic (ndinev) said : #6

You need to fix script like that ( I test it with hover but you can run it with your drag-drop)

import random
from random import choice

def position1():
    return Location(548,292)

def position2():
    return Location(633,293)

def position3():
    return Location(738,288)

def position4():
    return Location(817,284)

def randomDrop():
    positionOneToFour = [position1(), position2(), position3(), position4()]
    return random.choice(positionOneToFour)

def main():
    dragDrop("1573618403777.png",randomDrop())
    print('done')

main()

xyz_User (userseven) said : #7

Thanks Manfred Hampl, that solved my question.

xyz_User (userseven) said : #8

Thanks guys - Got me to think and I solved it by storing the location objects in a list then using randint method from random to call the list.

Thanks again!

TestMechanic (ndinev) said : #9

Thanks Manfred for solving the problem...