Need to click a checkbox against select text, where text is changing frequently

Asked by Shadab Manzar on 2017-04-13

Need to click a checkbox against select text, where text is changing frequently

Run One, i have only on option to select, i have to select apple
checkbox Apple

Run Two, I have two on option to select, i have to select mango
checkbox Apple
checkbox Mango

Run Three, I have three on option to select, i have to select orange
checkbox Apple
checkbox Mango
checkbox Orange

How to automate this case

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2017-04-13
Last reply:
2017-04-26
masuo (masuo-ohara) said : #2

I think that exists() feature is useful in this case.

if exists("orange.png",0):
    click("orange.png")
elif exists("mango.png",0):
    click("mango.png")
elif exists("apple.png",0):
    click("apple.png")

Shadab Manzar (smanzar27) said : #3

No problem is i do not know latest one, as i have to login in UI, and then i will come to know 3 one is present or not

its dynamic in nature, for every login new options comes

Mike (maestro+++) said : #4

It seems you want to move through a list that can change its size.

You can move using the arrow or tab keys, by moving a fixed offset or trying to locate some known visual features of the list members. After that it's normal Python to iterate until you find a condition that signals you've reached the last member of the list.

I guess however each new list member requires a new run of the script ie you need to remember from one run to the next how far you got down the list the last time you ran it. I guess that means writing logs to a file.

TestMechanic (ndinev) said : #5

You can find all checkboxes and sort them by Y coordinate. Then get last one. Here is sample function:

###
def Get_Nth_Image_Ysort(img,n):
    TestLog("Look Y sorted elements like " + str(img) + " and take number " + str(n))
    res=findAll(img)
    sorted_img = sorted(res, key=lambda m:m.y)
    sorted_img[n-1].highlight(2)
    return sorted_img[n-1]

###

You can enhance above function to look in region or to look checkbox by X or by X,Y

Can you help with this problem?

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

To post a message you must log in.