Handling dynamic objects

Asked by Preeti

I have 10 jobs created and i want to select any 1 job from it.and next time i want to select any other job.How will i select different Jobs each time and I dont want to take screenshots of each of the 10jobs.How to handle such objects dynamically??

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

What do you mean by "Job"? (give an example and a code snippet)

Are we talking about scripts in Sikuli IDE (Python/Jython level)?

Revision history for this message
Preeti (preetijasmine86) said :
#2

In my example as shown below i have to select 1 checkbox from 4 checkboxes appearing on the page.Everty time i visit that page i want to select the next(new) checkboxe ,I dont want to take the screenshots of each and every checkbox that i'll be selecting.I want some solution which could help me selecting the required checkbox at run time.Yes i am talking about scripts in Sikuli IDE.

eg:
(All these checkboxes are in 1page)

click("UWBPreeti2.png")
#next time click on this
click("fZ.png")
#next
click("UWBLaunchpad.png")
#next
click("UWBFormula1.png")

Imagine if i have n numbers of of checkbox in my application in 1page and everytime i want to select a new one?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

--- 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()

Revision history for this message
Preeti (preetijasmine86) said :
#4

Hi,Thanx for the answer i tried both the solutions.They worked but i am not able to understand the use of log.txt file in 2nd solution?
In both of the above solutions i still need to find the location of each box and it will be quite tedious for the end user.As my application has many boxes,according to the above solutions i need to define all of them before

box1 = Location(15,267)
box2 = Location(190,267)
box3
box4
and so on....

I was trying some thing like this :
X="English"
box1 = getRegionFromPSRM(X)
hover(box1)

Here "English" is any word on the page where i want to perform the action.The "English" word can be read from external file(testdata),so where ever i need to perform any action i just need to change the value in the external file(excel/csv).

But the problem was in case where "English" was written at more than 1 place in a page or there is word which is similar to "English" like "English1".

Revision history for this message
RaiMan (raimund-hocke) said :
#5

--- i am not able to understand the use of log.txt file in 2nd solution?
You said, you want to click the next box on the next run of the script. The file is used to save the click of the last run, so if you run the script tomorrow, it will click the next box.
If you want to click all boxes during one script run, you need a loop.

--- I was trying some thing like this : X="English"
getRegionFromPSRM() is for internal use only and not guaranteed to persist in future releases.
Use instead:
box1 = find("English")
hover(box1)

box1 now is a Match object and can be used as Region and contains more information than a Region about the find operation behind.

The features, functions and the API to use in the Sikuli IDE are here: http://sikuli.org/docx/

The Sikuli feature find("some text") is still experimental and has many oddities (see bug 710586).

--- use findAll()
You might use findAll() to find all checkboxes on the page. If you have them checked and unchecked, try to separate them using the similarity.

Can you help with this problem?

Provide an answer of your own, or ask Preeti for more information if necessary.

To post a message you must log in.