Drag drop to random (pre-defined) location

Asked by xyz_User

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:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
xyz_User (userseven) said :
#1

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

Revision history for this message
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()

Revision history for this message
Best Manfred Hampl (m-hampl) said :
#4

Have you tried

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

(note the position of the left parenthesis)

Revision history for this message
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

Revision history for this message
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()

Revision history for this message
xyz_User (userseven) said :
#7

Thanks Manfred Hampl, that solved my question.

Revision history for this message
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!

Revision history for this message
TestMechanic (ndinev) said :
#9

Thanks Manfred for solving the problem...