← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #185780]: Handling dynamic objects

 

Question #185780 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/185780

    Status: Open => Answered

RaiMan proposed the following answer:
--- access more than one element with one capture
Supposing, that the webpage content at least according to the checkboxes has some fixed pixel geometry, so you might measure the site once and then click using some offset to one reference image.

example (it needs the top of this page visible):

ref = find("sikuli-launchpad-logo.png")
box1 = Location(15,267)
box2 = Location(190,267)
hover(ref.offset(box1))
hover(ref.offset(box2))

sikuli-launchpad-logo.png is a capture of the Sikuli logo in the upper right corner.
box1 and box2 are the upper left yellow-pencil-buttons in the section "Question Information".
run the script in slow motion to see what happens.

- save the state over more than one script run
For a general solution, you have to implement some permanent storage, that you read and write during your runs.
The easiest one is to use a file stored in the script's folder.

example quick and dirty:

# at beginning of script
import os
maxBoxes = 4
logName = os.path.join(getBundlePath(), "log.txt")
try: # file does not exist first time
    log = file(logName) 
    last = int(log.read().strip())
    log.close()
except:
    last = -1
current = last +1 if last < maxBoxes-1 else 0

boxes = (box1, box2, box3, box4) # boxN have to be defined before as mentioned above
click(boxes[current])

log = file(logName, "w") # overwrite current
log.write(str(current))
log.close()

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.